mirror of
https://github.com/vlang/v.git
synced 2025-09-13 22:42:26 +03:00
parser: fix fixed array of option values (_ := [10]?int{}
) (#19392)
This commit is contained in:
parent
6d56639cc1
commit
175a3b2684
2 changed files with 9 additions and 1 deletions
|
@ -65,7 +65,8 @@ fn (mut p Parser) array_init(is_option bool) ast.ArrayInit {
|
|||
last_pos = p.tok.pos()
|
||||
p.check(.rsbr)
|
||||
if exprs.len == 1 && p.tok.line_nr == line_nr
|
||||
&& (p.tok.kind in [.name, .amp] || (p.tok.kind == .lsbr && p.is_array_type())) {
|
||||
&& (p.tok.kind in [.name, .amp, .question, .key_shared]
|
||||
|| (p.tok.kind == .lsbr && p.is_array_type())) {
|
||||
// [100]u8
|
||||
elem_type = p.parse_type()
|
||||
if p.table.sym(elem_type).name == 'byte' {
|
||||
|
|
7
vlib/v/tests/fixed_array_of_option_test.v
Normal file
7
vlib/v/tests/fixed_array_of_option_test.v
Normal file
|
@ -0,0 +1,7 @@
|
|||
fn test_fixed_array_of_option() {
|
||||
mut a := [3]?int{init: ?int(1)}
|
||||
a[0] = none
|
||||
a[1] = 2
|
||||
println(a)
|
||||
assert '${a}' == '[Option(none), Option(2), Option(1)]'
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue