Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/typeprof/core/ast/control.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,10 @@ def install0(genv)
@lenv.set_var(:"*expected_block_ret", nil)
end

@body.install(genv)
# A loop's break must not escape to an enclosing block.
@lenv.with_new_break_vtx do
@body.install(genv)
end

if expected_block_ret
@lenv.set_var(:"*expected_block_ret", expected_block_ret)
Expand Down
8 changes: 8 additions & 0 deletions lib/typeprof/core/env.rb
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,14 @@ def get_break_vtx
@break_vtx ||= Vertex.new(:break_vtx)
end

def with_new_break_vtx
previous_break_vtx = @break_vtx
@break_vtx = Vertex.new(:break_vtx)
yield
ensure
@break_vtx = previous_break_vtx
end

def push_ivar_narrowing(name, narrowing)
raise unless narrowing.is_a?(Narrowing::Constraint)
(@ivar_narrowings[name] ||= []) << narrowing
Expand Down
13 changes: 13 additions & 0 deletions scenario/control/break_in_loop.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
## update: test.rb
def foo(flag)
[1].each do
while flag
break :b
end
end
end

## assert: test.rb
class Object
def foo: (untyped) -> Array[Integer]
end
Loading