parser: fix cast or dump arguments ending with comma (#14552)

yuyi 2022-05-29 14:15:55 +08:00 committed by Chewing_Bever
parent 0a3d41c5d7
commit a396496b93
Signed by: Jef Roosens
GPG Key ID: B75D4F293C7052DB
4 changed files with 14 additions and 0 deletions

View File

@ -0,0 +1,4 @@
fn main() {
println(u8(1))
dump(1)
}

View File

@ -0,0 +1,4 @@
fn main() {
println(u8(1,),)
dump(1,)
}

View File

@ -272,6 +272,9 @@ pub fn (mut p Parser) check_expr(precedence int) ?ast.Expr {
p.next() p.next()
p.check(.lpar) p.check(.lpar)
expr := p.expr(0) expr := p.expr(0)
if p.tok.kind == .comma && p.peek_tok.kind == .rpar {
p.next()
}
p.check(.rpar) p.check(.rpar)
node = ast.DumpExpr{ node = ast.DumpExpr{
expr: expr expr: expr

View File

@ -2345,6 +2345,9 @@ pub fn (mut p Parser) name_expr() ast.Expr {
arg = p.expr(0) // len arg = p.expr(0) // len
has_arg = true has_arg = true
} }
if p.tok.kind == .comma && p.peek_tok.kind == .rpar {
p.next()
}
end_pos := p.tok.pos() end_pos := p.tok.pos()
p.check(.rpar) p.check(.rpar)
node = ast.CastExpr{ node = ast.CastExpr{