1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

parser: fix parsing array of options from a submodule (#17714)

This commit is contained in:
Felipe Pena
2023-03-20 05:36:22 -03:00
committed by GitHub
parent f1e9a8ff37
commit 74eac1de4e
2 changed files with 13 additions and 2 deletions

View File

@@ -2399,6 +2399,8 @@ pub fn (mut p Parser) name_expr() ast.Expr {
p.check(.question)
}
}
is_array := p.tok.kind == .lsbr
is_fixed_array := is_array && p.peek_tok.kind == .number
mut mod := ''
// p.warn('resetting')
p.expr_mod = ''
@@ -2553,8 +2555,6 @@ pub fn (mut p Parser) name_expr() ast.Expr {
|| (p.tok.kind == .lsbr && p.peek_tok.kind == .number && p.peek_token(2).kind == .rsbr
&& p.peek_token(4).kind == .lpar) {
// ?[]foo(), ?[1]foo, foo(), foo<int>() or type() cast
is_array := p.tok.kind == .lsbr
is_fixed_array := is_array && p.peek_tok.kind == .number
mut name := if is_array {
p.peek_token(if is_fixed_array { 3 } else { 2 }).lit
} else {

View File

@@ -0,0 +1,11 @@
import another_module as amodule
fn test_submodule_array_instance() {
x := ?[]amodule.SomeStruct{}
dump(x)
assert x == none
y := ?amodule.SomeStruct(none)
dump(y)
assert y == none
}