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

parser: fix parsing cast array syntax from another module (fix #17704) (#17739)

This commit is contained in:
Felipe Pena 2023-03-23 13:26:12 -03:00 committed by GitHub
parent 6b5c746146
commit 8693da4d36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 3 deletions

View File

@ -2556,15 +2556,23 @@ pub fn (mut p Parser) name_expr() ast.Expr {
}
}
} else if p.peek_tok.kind == .lpar || is_generic_call || is_generic_cast
|| (p.tok.kind == .lsbr && p.peek_tok.kind == .rsbr && p.peek_token(3).kind == .lpar)
|| (p.tok.kind == .lsbr && p.peek_tok.kind == .number && p.peek_token(2).kind == .rsbr
&& p.peek_token(4).kind == .lpar) {
|| (p.tok.kind == .lsbr && p.peek_tok.kind == .rsbr && (p.peek_token(3).kind == .lpar
|| p.peek_token(5).kind == .lpar)) || (p.tok.kind == .lsbr && p.peek_tok.kind == .number
&& p.peek_token(2).kind == .rsbr && (p.peek_token(4).kind == .lpar
|| p.peek_token(6).kind == .lpar)) {
// ?[]foo(), ?[1]foo, foo(), foo<int>() or type() cast
mut name := if is_array {
p.peek_token(if is_fixed_array { 3 } else { 2 }).lit
} else {
p.tok.lit
}
if is_fixed_array && p.peek_token(4).kind == .dot {
mod = name
name = p.peek_token(5).lit
} else if is_array && p.peek_token(3).kind == .dot {
mod = name
name = p.peek_token(4).lit
}
if mod.len > 0 {
name = '${mod}.${name}'
}

View File

@ -8,4 +8,12 @@ fn test_submodule_array_instance() {
y := ?amodule.SomeStruct(none)
dump(y)
assert y == none
w := ?[]amodule.SomeStruct(none)
dump(w)
assert w == none
z := ?[2]amodule.SomeStruct(none)
dump(z)
assert z == none
}