Skip to content

Handle keyword local variables correctly#1085

Merged
tompng merged 1 commit into
ruby:masterfrom
tompng:ignore_keyword_local_vars
Apr 9, 2025
Merged

Handle keyword local variables correctly#1085
tompng merged 1 commit into
ruby:masterfrom
tompng:ignore_keyword_local_vars

Conversation

@tompng
Copy link
Copy Markdown
Member

@tompng tompng commented Feb 13, 2025

Local variable can be a keyword. Fix a bug that IRB doesn't work in this case.

irb(main):001> {if:1} => {if:}
=> nil
irb(main):002> 1+2
irb(main):003> 
irb(main):004> (Can't submit input)

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.

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.
@tompng tompng force-pushed the ignore_keyword_local_vars branch from 7a901a0 to d6be3b9 Compare February 13, 2025 11:14
Comment thread lib/irb/completion.rb
Comment thread lib/irb/completion.rb
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)
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.

Same as the above.

@tompng tompng added the bug Something isn't working label Feb 13, 2025
@tompng tompng merged commit 6349b03 into ruby:master Apr 9, 2025
@tompng tompng deleted the ignore_keyword_local_vars branch April 9, 2025 10:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants