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

parser: fix wrong nodes generated for $something (#17969)

This commit is contained in:
Felipe Pena 2023-04-16 08:36:51 -03:00 committed by GitHub
parent 6e0204a614
commit 8e959ae5b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 1 deletions

View File

@ -0,0 +1,5 @@
vlib/v/checker/tests/invalid_comptime_test.vv:1:1: error: unexpected token `$`
1 | $fn func(a int) int {
| ^
2 | return a + a
3 | }

View File

@ -0,0 +1,7 @@
$fn func(a int) int {
return a + a
}
fn main() {
println(func(5))
}

View File

@ -754,7 +754,7 @@ pub fn (mut p Parser) top_stmt() ast.Stmt {
if p.peek_tok.kind == .key_for {
comptime_for_stmt := p.comptime_for()
return p.other_stmts(comptime_for_stmt)
} else {
} else if p.peek_tok.kind == .key_if {
if_expr := p.if_expr(true)
cur_stmt := ast.ExprStmt{
expr: if_expr
@ -765,6 +765,8 @@ pub fn (mut p Parser) top_stmt() ast.Stmt {
} else {
return p.other_stmts(cur_stmt)
}
} else {
return p.unexpected()
}
}
.hash {