diff --git a/vlib/v/ast/str.v b/vlib/v/ast/str.v index 3d981e847a..b44c95259a 100644 --- a/vlib/v/ast/str.v +++ b/vlib/v/ast/str.v @@ -357,10 +357,19 @@ pub fn (x Expr) str() string { if x.has_default { fields << 'init: ${x.default_expr.str()}' } + typ_str := global_table.type_to_str(x.elem_type) if fields.len > 0 { - return '[]T{${fields.join(', ')}}' + if x.is_fixed { + return '${x.exprs.str()}${typ_str}{${fields.join(', ')}}' + } else { + return '[]${typ_str}{${fields.join(', ')}}' + } } else { - return x.exprs.str() + if x.is_fixed { + return '${x.exprs.str()}${typ_str}{}' + } else { + return x.exprs.str() + } } } AsCast { diff --git a/vlib/v/gen/c/array.v b/vlib/v/gen/c/array.v index 1f29ce1a37..b1c978097a 100644 --- a/vlib/v/gen/c/array.v +++ b/vlib/v/gen/c/array.v @@ -191,12 +191,14 @@ fn (mut g Gen) fixed_array_init(node ast.ArrayInit, array_type Type, var_name st info := array_type.unaliased_sym.info as ast.ArrayFixed arr_info := elem_sym.array_fixed_info() g.expr(ast.ArrayInit{ + exprs: [ast.IntegerLiteral{}] typ: node.elem_type elem_type: arr_info.elem_type }) for _ in 1 .. info.size { g.write(', ') g.expr(ast.ArrayInit{ + exprs: [ast.IntegerLiteral{}] typ: node.elem_type elem_type: arr_info.elem_type }) diff --git a/vlib/v/gen/c/dumpexpr.v b/vlib/v/gen/c/dumpexpr.v index 0dee88265d..7de98fc964 100644 --- a/vlib/v/gen/c/dumpexpr.v +++ b/vlib/v/gen/c/dumpexpr.v @@ -60,6 +60,14 @@ fn (mut g Gen) dump_expr(node ast.DumpExpr) { g.expr(node.expr) g.write('.data)') g.inside_opt_or_res = old_inside_opt_or_res + } else if node.expr is ast.ArrayInit { + if node.expr.is_fixed { + s := g.typ(node.expr.typ) + if !node.expr.has_index { + g.write('(${s})') + } + } + g.expr(node.expr) } else { old_inside_opt_or_res := g.inside_opt_or_res g.inside_opt_or_res = true diff --git a/vlib/v/slow_tests/inout/dump_multi_fixed_array_init.out b/vlib/v/slow_tests/inout/dump_multi_fixed_array_init.out new file mode 100644 index 0000000000..76b6909bf7 --- /dev/null +++ b/vlib/v/slow_tests/inout/dump_multi_fixed_array_init.out @@ -0,0 +1 @@ +[vlib/v/slow_tests/inout/dump_multi_fixed_array_init.vv:2] [2][3]int{}: [[0, 0, 0], [0, 0, 0]] diff --git a/vlib/v/slow_tests/inout/dump_multi_fixed_array_init.vv b/vlib/v/slow_tests/inout/dump_multi_fixed_array_init.vv new file mode 100644 index 0000000000..3fd7ecd991 --- /dev/null +++ b/vlib/v/slow_tests/inout/dump_multi_fixed_array_init.vv @@ -0,0 +1,3 @@ +fn main() { + dump([2][3]int{}) +} diff --git a/vlib/v/slow_tests/inout/printing_multi_fixed_array_init.out b/vlib/v/slow_tests/inout/printing_multi_fixed_array_init.out new file mode 100644 index 0000000000..033bad879b --- /dev/null +++ b/vlib/v/slow_tests/inout/printing_multi_fixed_array_init.out @@ -0,0 +1 @@ +[[0, 0, 0], [0, 0, 0]] diff --git a/vlib/v/slow_tests/inout/printing_multi_fixed_array_init.vv b/vlib/v/slow_tests/inout/printing_multi_fixed_array_init.vv new file mode 100644 index 0000000000..23c0282264 --- /dev/null +++ b/vlib/v/slow_tests/inout/printing_multi_fixed_array_init.vv @@ -0,0 +1,3 @@ +fn main() { + println([2][3]int{}) +}