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 { if p.expecting_type {
// parse json.decode type (`json.decode([]User, s)`) // parse json.decode type (`json.decode([]User, s)`)
node = p.name_expr() node = p.name_expr()
} else if p.is_amp && p.peek_tok.kind == .rsbr && p.peek_token(3).kind != .lcbr { } else if p.is_amp && p.peek_tok.kind == .rsbr {
pos := p.tok.pos() mut n := 2
typ := p.parse_type() mut peek_n_tok := p.peek_token(n)
typname := p.table.sym(typ).name for peek_n_tok.kind in [.name, .dot] {
p.check(.lpar) n++
expr := p.expr(0) peek_n_tok = p.peek_token(n)
p.check(.rpar) }
node = ast.CastExpr{ if peek_n_tok.kind != .lcbr {
typ: typ pos := p.tok.pos()
typname: typname typ := p.parse_type()
expr: expr typname := p.table.sym(typ).name
pos: pos 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 { } else {
node = p.array_init(false) 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
}