diff --git a/vlib/v/gen/c/fn.v b/vlib/v/gen/c/fn.v index 15238e7262..e3ecc60309 100644 --- a/vlib/v/gen/c/fn.v +++ b/vlib/v/gen/c/fn.v @@ -778,7 +778,13 @@ fn (mut g Gen) method_call(node ast.CallExpr) { && node.name in ['first', 'last', 'repeat'] { g.write('*') } - g.expr(node.left) + if node.left is ast.MapInit { + g.write('(map[]){') + g.expr(node.left) + g.write('}[0]') + } else { + g.expr(node.left) + } if node.from_embed_type != 0 { embed_name := typ_sym.embed_name() if node.left_type.is_ptr() { diff --git a/vlib/v/tests/map_literals_method_call_test.v b/vlib/v/tests/map_literals_method_call_test.v new file mode 100644 index 0000000000..83b7a42cde --- /dev/null +++ b/vlib/v/tests/map_literals_method_call_test.v @@ -0,0 +1,10 @@ +fn test_map_literals_method_call() { + a := 1 in map{ + 1: 1 + }.keys().map(map{ + 1: 1 + }[it]) + + println(a) + assert a +}