diff --git a/vlib/v/checker/tests/with_check_option/v_tictactoe.out b/vlib/v/checker/tests/with_check_option/v_tictactoe.out index f41153ee52..8682a24390 100644 --- a/vlib/v/checker/tests/with_check_option/v_tictactoe.out +++ b/vlib/v/checker/tests/with_check_option/v_tictactoe.out @@ -1,4 +1,4 @@ -vlib/v/checker/tests/with_check_option/v_tictactoe.vv:4:31: error: expected `init:`, not `len` +vlib/v/checker/tests/with_check_option/v_tictactoe.vv:4:31: error: `len` and `cap` are invalid attributes for fixed array dimension 2 | 3 | fn new_board() [][]string { 4 | mut board := [3][]string{ len: 3, init: []string{ len: 3, init: '' } } diff --git a/vlib/v/parser/containers.v b/vlib/v/parser/containers.v index bc2847fbb1..481c0af2ef 100644 --- a/vlib/v/parser/containers.v +++ b/vlib/v/parser/containers.v @@ -80,7 +80,12 @@ fn (mut p Parser) array_init() ast.ArrayInit { pos := p.tok.pos() n := p.check_name() if n != 'init' { - p.error_with_pos('expected `init:`, not `$n`', pos) + if is_fixed { + p.error_with_pos('`len` and `cap` are invalid attributes for fixed array dimension', + pos) + } else { + p.error_with_pos('expected `init:`, not `$n`', pos) + } return ast.ArrayInit{} } p.check(.colon) diff --git a/vlib/v/parser/tests/fixed_arr_len_cap_attr_err.out b/vlib/v/parser/tests/fixed_arr_len_cap_attr_err.out new file mode 100644 index 0000000000..8a96a6d2a1 --- /dev/null +++ b/vlib/v/parser/tests/fixed_arr_len_cap_attr_err.out @@ -0,0 +1,6 @@ +vlib/v/parser/tests/fixed_arr_len_cap_attr_err.vv:2:31: error: `len` and `cap` are invalid attributes for fixed array dimension + 1 | fn new_board() [][]string { + 2 | mut board := [3][]string{ len: 3, init: []string{ len: 3, init: '' } } + | ~~~ + 3 | for i in 0..9 { + 4 | board[i / 3][i % 3] = (i + 1).str() diff --git a/vlib/v/parser/tests/fixed_arr_len_cap_attr_err.vv b/vlib/v/parser/tests/fixed_arr_len_cap_attr_err.vv new file mode 100644 index 0000000000..a35bea5515 --- /dev/null +++ b/vlib/v/parser/tests/fixed_arr_len_cap_attr_err.vv @@ -0,0 +1,7 @@ +fn new_board() [][]string { + mut board := [3][]string{ len: 3, init: []string{ len: 3, init: '' } } + for i in 0..9 { + board[i / 3][i % 3] = (i + 1).str() + } + return board +}