Skip to content

Commit

Permalink
parser: fix fixed array of option values (_ := [10]?int{}) (vlang#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 authored and Wertzui123 committed Oct 8, 2023
1 parent 587a11e commit 6a61862
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion vlib/v/parser/containers.v
Original file line number Diff line number Diff line change
Expand Up @@ -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' {
Expand Down
7 changes: 7 additions & 0 deletions vlib/v/tests/fixed_array_of_option_test.v
Original file line number Diff line number Diff line change
@@ -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)]'
}

0 comments on commit 6a61862

Please sign in to comment.