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

parser: fix comptime_for in repl (script mode) (fix #5976) (#17963)

This commit is contained in:
yuyi 2023-04-15 19:28:01 +08:00 committed by GitHub
parent 2179db37ee
commit 7c9f273e33
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 8 deletions

View File

@ -751,15 +751,20 @@ pub fn (mut p Parser) top_stmt() ast.Stmt {
if p.peek_tok.kind == .eof {
return p.unexpected(got: 'eof')
}
if_expr := p.if_expr(true)
cur_stmt := ast.ExprStmt{
expr: if_expr
pos: if_expr.pos
}
if comptime_if_expr_contains_top_stmt(if_expr) {
return cur_stmt
if p.peek_tok.kind == .key_for {
comptime_for_stmt := p.comptime_for()
return p.other_stmts(comptime_for_stmt)
} else {
return p.other_stmts(cur_stmt)
if_expr := p.if_expr(true)
cur_stmt := ast.ExprStmt{
expr: if_expr
pos: if_expr.pos
}
if comptime_if_expr_contains_top_stmt(if_expr) {
return cur_stmt
} else {
return p.other_stmts(cur_stmt)
}
}
}
.hash {

View File

@ -0,0 +1,10 @@
struct Person {
name string
age int
}
$for field in Person.fields {
println(field.name)
}
===output===
name
age