Skip to content

Fix local variable inference across retry - #493

Merged
mame merged 1 commit into
ruby:masterfrom
pvcresin:fix-retry-inference
Sep 28, 2026
Merged

mame merged 1 commit into
ruby:masterfrom
pvcresin:fix-retry-inference

Conversation

@pvcresin

@pvcresin pvcresin commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

Motivation / Background

TypeProf does not include local variable updates made in a rescue clause when that clause uses retry.

def foo
  n = 1
  begin
    raise if rand < 0.5
    n
  rescue
    n = "str"
    retry
  end
end

A later attempt can return the updated String, but TypeProf currently infers only Integer.

Detail

  • Track locals modified by retrying rescue clauses and feed their state back into the begin body.
  • Keep retry detection scoped correctly when a nested begin body contains a retry.
  • Move the regression case from known issues to the active retry scenario.

Verification

  • ruby -Itest -e 'require "scenario_compiler"; ScenarioCompiler.new(Dir.glob("scenario/control/*.rb")).run' (35 tests, 52 assertions)
  • git diff --check

@mame mame left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, looks good to me!

@mame
mame merged commit 5f6e05b into ruby:master Sep 28, 2026
6 checks passed
@pvcresin
pvcresin deleted the fix-retry-inference branch September 28, 2026 14:04
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.

2 participants