parser: fix fixed array of option values (_ := [10]?int{}) (#19392)

This commit is contained in:
yuyi 2023-09-20 20:34:42 +08:00 committed by GitHub
parent 6d56639cc1
commit 175a3b2684
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View file

@ -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' {

View 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)]'
}