From 704f38d87fdc03876a5a293825ff7e000655849b Mon Sep 17 00:00:00 2001 From: yuyi Date: Sun, 10 Jan 2021 13:58:31 +0800 Subject: [PATCH] parser: fix multi fixed arrays init (#7996) --- vlib/builtin/array_test.v | 5 +++++ vlib/v/parser/containers.v | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/vlib/builtin/array_test.v b/vlib/builtin/array_test.v index 3d6a9762c3..ecd721bde7 100644 --- a/vlib/builtin/array_test.v +++ b/vlib/builtin/array_test.v @@ -1305,3 +1305,8 @@ fn test_array_of_map_insert() { println(x) assert '$x' == "[{}, {}, {'123': 123}, {}]" } + +fn test_multi_fixed_array_init() { + a := [3][3]int{} + assert '$a' == '[[0, 0, 0], [0, 0, 0], [0, 0, 0]]' +} diff --git a/vlib/v/parser/containers.v b/vlib/v/parser/containers.v index 20af0c877b..716f698d0e 100644 --- a/vlib/v/parser/containers.v +++ b/vlib/v/parser/containers.v @@ -54,7 +54,7 @@ fn (mut p Parser) array_init() ast.ArrayInit { } last_pos = p.tok.position() p.check(.rsbr) - if exprs.len == 1 && p.tok.kind in [.name, .amp] && p.tok.line_nr == line_nr { + if exprs.len == 1 && p.tok.kind in [.name, .amp, .lsbr] && p.tok.line_nr == line_nr { // [100]byte elem_type = p.parse_type() is_fixed = true