parser: snake_case check; array: mutable array test

pull/4232/head
Alexander Medvednikov 2020-04-04 14:09:58 +02:00
parent 4c6db7a64e
commit 46aed151ab
3 changed files with 26 additions and 1 deletions

View File

@ -313,6 +313,27 @@ fn test_mut_slice() {
*/
}
fn double_up(a mut []int) {
for i := 0; i < a.len; i++ {
a[i] = a[i]*2
}
}
fn double_up_v2(a mut []int) {
for i, val in a {
a[i] = a[i]*2 // or val*2, doesn't matter
}
}
fn test_mut_arg() {
mut arr := [1,2,3,4,5,6,7,8,9,10]
double_up(mut arr)
assert arr.str() == '[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]'
arr = [1,2,3,4,5,6,7,8,9,10]
double_up_v2(mut arr)
assert arr.str() == '[2, 4, 6, 8, 10, 12, 14, 16, 18, 20]'
}
fn test_clone() {
nums := [1, 2, 3, 4, 100]
nums2 := nums.clone()

View File

@ -6,6 +6,7 @@ module parser
import (
v.ast
v.table
v.scanner
)
pub fn (p mut Parser) call_expr(is_c bool, mod string) ast.CallExpr {
@ -103,6 +104,9 @@ fn (p mut Parser) fn_decl() ast.FnDecl {
if p.tok.kind == .name {
// TODO high order fn
name = p.check_name()
if !is_c && !p.pref.translated && scanner.contains_capital(name) {
p.error('function names cannot contain uppercase letters, use snake_case instead')
}
}
if p.tok.kind in [.plus, .minus, .mul, .div, .mod] {
name = p.tok.kind.str() // op_to_fn_name()

View File

@ -59,7 +59,7 @@ pub fn formated_error(kind string /*error or warn*/, emsg string, filepath strin
mut source_context := ''
//
final_position := if emanager.support_color {
term.bold(term.white(position))
term.bold(position) // term.white(position))
} else {
position
}