cgen: fix error for printing multi fixed array (#14141)

master
yuyi 2022-04-25 19:42:05 +08:00 committed by GitHub
parent 283d181047
commit aeba110d01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 1 deletions

View File

@ -78,7 +78,7 @@ fn (mut g Gen) array_init(node ast.ArrayInit) {
g.inside_lambda = false
return
}
need_tmp_var := g.inside_call && !g.inside_struct_init
need_tmp_var := g.inside_call && !g.inside_struct_init && node.exprs.len == 0
mut stmt_str := ''
mut tmp_var := ''
if need_tmp_var {

View File

@ -2044,6 +2044,12 @@ fn (mut g Gen) ref_or_deref_arg(arg ast.CallArg, expected_type ast.Type, lang as
g.expr(arg.expr)
g.write('->val')
return
} else if arg.expr is ast.ArrayInit {
if arg.expr.is_fixed {
if !arg.expr.has_it {
g.write('(${g.typ(arg.expr.typ)})')
}
}
}
g.expr_with_cast(arg.expr, arg_typ, expected_type)
if needs_closing {

View File

@ -0,0 +1 @@
[[1, 2], [3, 3]]

View File

@ -0,0 +1,4 @@
fn main() {
a := [[1, 2]!, [3, 3]!]!
println([[a[0][0], a[0][1]]!, [a[1][0], a[1][1]]!]!)
}