checker: fix break inside anon fn (#10914)

pull/10939/head
Daniel Däschle 2021-07-23 00:13:36 +02:00 committed by GitHub
parent 44828cbb29
commit f40090e8ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 1 deletions

View File

@ -4614,7 +4614,7 @@ fn (mut c Checker) block(node ast.Block) {
}
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)
}
if node.label.len > 0 {

View File

@ -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 | }()

View File

@ -0,0 +1,8 @@
fn main() {
for true {
_ := fn () int {
break
return 3
}()
}
}