diff --git a/vlib/v/parser/for.v b/vlib/v/parser/for.v index 6b70ac40e6..99d8133355 100644 --- a/vlib/v/parser/for.v +++ b/vlib/v/parser/for.v @@ -9,7 +9,11 @@ import v.table fn (mut p Parser) for_stmt() ast.Stmt { p.check(.key_for) pos := p.tok.position() + prev_branch_parent_pos := p.branch_parent_pos p.branch_parent_pos = pos.pos + defer { + p.branch_parent_pos = prev_branch_parent_pos + } p.open_scope() p.inside_for = true if p.tok.kind == .key_match { diff --git a/vlib/v/tests/valgrind/1.strings_and_arrays.v b/vlib/v/tests/valgrind/1.strings_and_arrays.v index 32f83224b7..41b4985376 100644 --- a/vlib/v/tests/valgrind/1.strings_and_arrays.v +++ b/vlib/v/tests/valgrind/1.strings_and_arrays.v @@ -275,6 +275,9 @@ fn free_before_break() { for { cc := [7, 8, 9] if true { + if true { + break + } break } }