Skip to content

Scope break values to loop bodies - #501

Open
pvcresin wants to merge 1 commit into
ruby:masterfrom
pvcresin:fix-loop-break-scope
Open

pvcresin wants to merge 1 commit into
ruby:masterfrom
pvcresin:fix-loop-break-scope

Conversation

@pvcresin

@pvcresin pvcresin commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

A break inside a while nested in an Array#each block is currently connected to the block's break vertex. For foo(flag), TypeProf infers (:b | Array[Integer]), as if each could return the loop's break value.

This is not an infinite loop: when flag is truthy, the body breaks immediately; otherwise, the while exits without entering the body. Array#each should therefore retain its Array[Integer] return type.

Give each loop body its own break vertex and restore the enclosing vertex after analysis so a loop-local break cannot escape the surrounding block.

Test

Ran the focused scenario set: break_in_loop.rb, break.rb, break2.rb, and loop.rb (4 scenarios, 9 assertions).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant