mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: improve error for fixed array, when it has len
and cap
attributes in the initialisation list (#16120)
This commit is contained in:
parent
ffcdac4201
commit
ac63fa1b11
@ -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 |
|
2 |
|
||||||
3 | fn new_board() [][]string {
|
3 | fn new_board() [][]string {
|
||||||
4 | mut board := [3][]string{ len: 3, init: []string{ len: 3, init: '' } }
|
4 | mut board := [3][]string{ len: 3, init: []string{ len: 3, init: '' } }
|
||||||
|
@ -80,7 +80,12 @@ fn (mut p Parser) array_init() ast.ArrayInit {
|
|||||||
pos := p.tok.pos()
|
pos := p.tok.pos()
|
||||||
n := p.check_name()
|
n := p.check_name()
|
||||||
if n != 'init' {
|
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{}
|
return ast.ArrayInit{}
|
||||||
}
|
}
|
||||||
p.check(.colon)
|
p.check(.colon)
|
||||||
|
6
vlib/v/parser/tests/fixed_arr_len_cap_attr_err.out
Normal file
6
vlib/v/parser/tests/fixed_arr_len_cap_attr_err.out
Normal file
@ -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()
|
7
vlib/v/parser/tests/fixed_arr_len_cap_attr_err.vv
Normal file
7
vlib/v/parser/tests/fixed_arr_len_cap_attr_err.vv
Normal file
@ -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
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user