cgen: fix error of the map literals method call (#10791)

pull/10804/head
yuyi 2021-07-15 03:03:47 +08:00 committed by GitHub
parent 9c710b2a34
commit fe1cf2ea26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 1 deletions

View File

@ -778,7 +778,13 @@ fn (mut g Gen) method_call(node ast.CallExpr) {
&& node.name in ['first', 'last', 'repeat'] { && node.name in ['first', 'last', 'repeat'] {
g.write('*') 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 { if node.from_embed_type != 0 {
embed_name := typ_sym.embed_name() embed_name := typ_sym.embed_name()
if node.left_type.is_ptr() { if node.left_type.is_ptr() {

View File

@ -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
}