mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
@@ -751,15 +751,20 @@ pub fn (mut p Parser) top_stmt() ast.Stmt {
|
|||||||
if p.peek_tok.kind == .eof {
|
if p.peek_tok.kind == .eof {
|
||||||
return p.unexpected(got: 'eof')
|
return p.unexpected(got: 'eof')
|
||||||
}
|
}
|
||||||
if_expr := p.if_expr(true)
|
if p.peek_tok.kind == .key_for {
|
||||||
cur_stmt := ast.ExprStmt{
|
comptime_for_stmt := p.comptime_for()
|
||||||
expr: if_expr
|
return p.other_stmts(comptime_for_stmt)
|
||||||
pos: if_expr.pos
|
|
||||||
}
|
|
||||||
if comptime_if_expr_contains_top_stmt(if_expr) {
|
|
||||||
return cur_stmt
|
|
||||||
} else {
|
} 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 {
|
.hash {
|
||||||
|
|||||||
10
vlib/v/slow_tests/repl/comptime_for.repl
Normal file
10
vlib/v/slow_tests/repl/comptime_for.repl
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
struct Person {
|
||||||
|
name string
|
||||||
|
age int
|
||||||
|
}
|
||||||
|
$for field in Person.fields {
|
||||||
|
println(field.name)
|
||||||
|
}
|
||||||
|
===output===
|
||||||
|
name
|
||||||
|
age
|
||||||
Reference in New Issue
Block a user