diff --git a/vlib/v/gen/c/index.v b/vlib/v/gen/c/index.v index ab975fc131..b025f13caa 100644 --- a/vlib/v/gen/c/index.v +++ b/vlib/v/gen/c/index.v @@ -350,7 +350,13 @@ fn (mut g Gen) index_of_map(node ast.IndexExpr, sym ast.TypeSymbol) { g.write('->val') } g.write(', &($key_type_str[]){') + old_is_arraymap_set := g.is_arraymap_set + old_is_assign_lhs := g.is_assign_lhs + g.is_arraymap_set = false + g.is_assign_lhs = false g.expr(node.index) + g.is_arraymap_set = old_is_arraymap_set + g.is_assign_lhs = old_is_assign_lhs g.write('}') if elem_typ.kind == .function { g.write(', &(voidptr[]) { ') diff --git a/vlib/v/tests/nested_map_test.v b/vlib/v/tests/nested_map_test.v index 3cf12bc1dd..140cbce92e 100644 --- a/vlib/v/tests/nested_map_test.v +++ b/vlib/v/tests/nested_map_test.v @@ -32,3 +32,15 @@ fn test_map_of_map_to_struct() { foos['zza']['zzb'].name = 'baz' assert foos['zza']['zzb'].name == 'baz' } + +fn test_map_of_map_key_plus_assign() { + m := { + 'a': 'x' + } + mut n := { + 'x': 1 + } + n[m['a']] += 2 + println(n) + assert n['x'] == 3 +}