Repository navigation
Conversation
WorkSpace#initialize unconditionally ran `local_variable_set(:_, nil)`. When the binding already had a `_` local, Binding#local_variable_set overwrote the program's variable, so `_ = :mine; binding.irb` showed nil. The debugger's IRB console mode creates a new WorkSpace at every prompt, so the value was reset each time. Only set `_` to nil when the binding does not already define it. Refs ruby#891 Co-Authored-By: Claude Haiku 5.5 <[email protected]>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #891. Works together with ruby/debug#1188.
WorkSpace#initializealways called@binding.local_variable_set(:_, nil). If the binding already has a_local,Binding#local_variable_setoverwrites the program's variable, so_ = :mine; binding.irbshowsnil. The debugger's IRB console mode creates a new WorkSpace at every prompt, so the value is reset each time.This change only sets
_to nil when the binding doesn't already define it.Tests:
test_workspace_keeps_existing_underscore(new): fails before the fix, passes after.test_workspace_defines_underscore_as_nil_when_absent(new): existing behavior, passes.test_irb_console_mode_keeps_program_defined_underscore(new, debugger integration): fails before the fix, passes after.test_context_mode_ruby_box, which also fails without this change on Ruby 4.0.9 here.Known separate question, not changed here:
Context#set_last_valuestill writes_after each evaluated expression, so a program's_becomes the last result after the first expression in plainbinding.irb. I left that as is.🤖 Generated with Claude Code