mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: fix break inside anon fn (#10914)
This commit is contained in:
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) {
|
||||
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 {
|
||||
|
7
vlib/v/checker/tests/break_anon_fn_err.out
Normal file
7
vlib/v/checker/tests/break_anon_fn_err.out
Normal 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 | }()
|
8
vlib/v/checker/tests/break_anon_fn_err.vv
Normal file
8
vlib/v/checker/tests/break_anon_fn_err.vv
Normal file
@ -0,0 +1,8 @@
|
||||
fn main() {
|
||||
for true {
|
||||
_ := fn () int {
|
||||
break
|
||||
return 3
|
||||
}()
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user