diff --git a/vlib/builtin/map_test.v b/vlib/builtin/map_test.v index c6003cfc70..b1bb61db91 100644 --- a/vlib/builtin/map_test.v +++ b/vlib/builtin/map_test.v @@ -73,8 +73,8 @@ fn test_string_map() { fn test_large_map() { //ticks := time.ticks() mut nums := map[string]int - N := 30 * 1000 - for i in 0..N { + n := 30 * 1000 + for i in 0..n { key := i.str() nums[key] = i } @@ -166,7 +166,8 @@ fn mut_map(m mut map[string]int) { fn test_mut_arg() { mut m := map[string]int mut_map(mut m) - assert m['a'] == 10 + a := m['a'] + assert a == 10 } fn test_delete() { @@ -175,8 +176,8 @@ fn test_delete() { m['two'] = 2 println(m['two']) // => "2" m.delete('two') - println(m['two']) // => 0 - assert 'two' in m == false + println(m['two'].str()) // => 0 + assert ('two' in m) == false println('two' in m) // => true, on Linux and Windows <-- wrong ! } @@ -205,4 +206,3 @@ fn test_delete_size() { } } } - diff --git a/vlib/v/ast/ast.v b/vlib/v/ast/ast.v index 6b12b397e7..faab350cda 100644 --- a/vlib/v/ast/ast.v +++ b/vlib/v/ast/ast.v @@ -337,6 +337,7 @@ pub: index Expr // [0], [start..end] etc mut: container_type table.Type // array, map, fixed array + is_setter bool } pub struct IfExpr { diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index ecfbf6c3f5..8e5a946714 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -77,6 +77,9 @@ pub fn (x Expr) str() string { ParExpr { return it.expr.str() } + IndexExpr { + return '${it.left.str()}[${it.index.str()}]' + } else { return '[unhandled expr type ${typeof(x)}]' } diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index 489c713a30..7da8751dcf 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -1681,8 +1681,8 @@ fn (g mut Gen) index_expr(node ast.IndexExpr) { is_selector = true } else {} - } - if g.is_assign_lhs && !is_selector { + } + if g.is_assign_lhs && !is_selector && node.is_setter { g.is_array_set = true g.write('array_set(&') g.expr(node.left) diff --git a/vlib/v/parser/parser.v b/vlib/v/parser/parser.v index 9630be02f6..b533d8f327 100644 --- a/vlib/v/parser/parser.v +++ b/vlib/v/parser/parser.v @@ -436,6 +436,13 @@ pub fn (p mut Parser) assign_expr(left ast.Expr) ast.AssignExpr { op := p.tok.kind p.next() val := p.expr(0) + match left { + ast.IndexExpr { + //it.mark_as_setter() + it.is_setter = true + } + else{} + } node := ast.AssignExpr{ left: left val: val