Handle keyword local variables correctly#1085
Merged
tompng merged 1 commit intoruby:masterfrom Apr 9, 2025
Merged
Conversation
Local variable can be a keyword. Example: `def f(if:0, and:0); binding.irb; end` IRB prepends local variable assignment code `a=_=nil;` to the input code but keyword local variables should be excluded.
7a901a0 to
d6be3b9
Compare
st0012
reviewed
Feb 13, 2025
| else | ||
| candidates = (bind.eval_methods | bind.eval_private_methods | bind.local_variables | bind.eval_instance_variables | bind.eval_class_constants).collect{|m| m.to_s} | ||
| candidates |= ReservedWords | ||
| candidates |= RubyLex::RESERVED_WORDS.map(&:to_s) |
st0012
approved these changes
Apr 8, 2025
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.
Local variable can be a keyword. Fix a bug that IRB doesn't work in this case.
IRB prepends local variable assignment code
a=_=nil;to the input code. (Because Ruby code is parsed differently depending on local variable existence)Prepending
if=_=nil;cause bug in this case.