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

parser: fix parse error in the type of a ref array when the element type is a structure of another mod(fix #19033) (#19039)

This commit is contained in:
shove 2023-08-03 14:25:03 +08:00 committed by GitHub
parent fe9bdd4168
commit b556f1302f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 12 deletions

View File

@ -182,18 +182,28 @@ fn (mut p Parser) check_expr(precedence int) !ast.Expr {
if p.expecting_type {
// parse json.decode type (`json.decode([]User, s)`)
node = p.name_expr()
} else if p.is_amp && p.peek_tok.kind == .rsbr && p.peek_token(3).kind != .lcbr {
pos := p.tok.pos()
typ := p.parse_type()
typname := p.table.sym(typ).name
p.check(.lpar)
expr := p.expr(0)
p.check(.rpar)
node = ast.CastExpr{
typ: typ
typname: typname
expr: expr
pos: pos
} else if p.is_amp && p.peek_tok.kind == .rsbr {
mut n := 2
mut peek_n_tok := p.peek_token(n)
for peek_n_tok.kind in [.name, .dot] {
n++
peek_n_tok = p.peek_token(n)
}
if peek_n_tok.kind != .lcbr {
pos := p.tok.pos()
typ := p.parse_type()
typname := p.table.sym(typ).name
p.check(.lpar)
expr := p.expr(0)
p.check(.rpar)
node = ast.CastExpr{
typ: typ
typname: typname
expr: expr
pos: pos
}
} else {
node = p.array_init(false)
}
} else {
node = p.array_init(false)

View File

@ -0,0 +1,17 @@
import another_module
struct SomeStruct {}
fn type_from_another_mod() {
_ = &[]another_module.SomeStruct{}
}
fn type_from_current_mod() {
_ = &[]SomeStruct{}
}
fn test_parse_type_of_ref_array() {
type_from_another_mod()
type_from_current_mod()
assert true
}