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

master
yuyi 2022-05-29 14:15:55 +08:00 committed by GitHub
parent 63d15086e7
commit 79d861ad4f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.check(.lpar)
expr := p.expr(0)
if p.tok.kind == .comma && p.peek_tok.kind == .rpar {
p.next()
}
p.check(.rpar)
node = ast.DumpExpr{
expr: expr

View File

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