checker: fix break inside anon fn (#10914)
parent
44828cbb29
commit
f40090e8ff
|
@ -4614,7 +4614,7 @@ fn (mut c Checker) block(node ast.Block) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (mut c Checker) branch_stmt(node ast.BranchStmt) {
|
fn (mut c Checker) branch_stmt(node ast.BranchStmt) {
|
||||||
if c.in_for_count == 0 {
|
if c.in_for_count == 0 || c.inside_anon_fn {
|
||||||
c.error('$node.kind.str() statement not within a loop', node.pos)
|
c.error('$node.kind.str() statement not within a loop', node.pos)
|
||||||
}
|
}
|
||||||
if node.label.len > 0 {
|
if node.label.len > 0 {
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
vlib/v/checker/tests/break_anon_fn_err.vv:4:4: error: break statement not within a loop
|
||||||
|
2 | for true {
|
||||||
|
3 | _ := fn () int {
|
||||||
|
4 | break
|
||||||
|
| ~~~~~
|
||||||
|
5 | return 3
|
||||||
|
6 | }()
|
|
@ -0,0 +1,8 @@
|
||||||
|
fn main() {
|
||||||
|
for true {
|
||||||
|
_ := fn () int {
|
||||||
|
break
|
||||||
|
return 3
|
||||||
|
}()
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue