diff --git a/vlib/v/gen/cgen.v b/vlib/v/gen/cgen.v index e1a686c855..c1574973f0 100644 --- a/vlib/v/gen/cgen.v +++ b/vlib/v/gen/cgen.v @@ -73,6 +73,7 @@ mut: inside_ternary int // ?: comma separated statements on a single line inside_map_postfix bool // inside map++/-- postfix expr inside_map_infix bool // inside map<val') @@ -4165,7 +4172,7 @@ fn (mut g Gen) index_expr(node ast.IndexExpr) { zero := g.type_default(info.value_type) g.write('$zero })))') } - } else if (g.inside_map_postfix || g.inside_map_infix) || + } else if g.inside_map_postfix || g.inside_map_infix || g.inside_map_index || (g.is_assign_lhs && !g.is_array_set && get_and_set_types) { zero := g.type_default(info.value_type) diff --git a/vlib/v/tests/map_high_order_assign_test.v b/vlib/v/tests/map_high_order_assign_test.v new file mode 100644 index 0000000000..024d7ef59d --- /dev/null +++ b/vlib/v/tests/map_high_order_assign_test.v @@ -0,0 +1,6 @@ +fn test_high_order_map_assign() { + mut m := map[string]map[string]int + m['hello']['hi'] = 1 + println(m) + assert '$m' == "{'hello': {'hi': 1}}" +}