Skip to content

Allow assigning to local variable conflicting with command name - #1108

Closed
tompng wants to merge 1 commit into
ruby:masterfrom
tompng:assignment_is_not_command
Closed

tompng wants to merge 1 commit into
ruby:masterfrom
tompng:assignment_is_not_command

Conversation

@tompng

@tompng tompng commented Jul 1, 2024

Copy link
Copy Markdown
Member

n = 1 n += 1 n **= 1 n &&= 1 will be a ruby expression, not a shorthand of next command.

(ruby) n = 1
1
(ruby) n += 100
101
(rdbg) p n    # command
=> 101
(rdbg) n    # next command

Background

IRB's command recognization is changed in ruby/irb#961 (merged but not released yet) to fix some reported issues

irb(main):001>measure = Measure.first
=> error
irb(main):002> jobs = Job.where(id: ids)
deprecation message of Multi-irb

The rules are:

  • Multiline input is not a command
  • Assign-like expression is not a command, checked by a simple regexp and String#start_with?
  • If method with the same name as command is defined, follow the method override policy of each command
  • If local variable with the same name as command is defined, it is not a command

This pull request will change debug's command recognizing rule similar to IRB style.

Implementation difference between IRB

Debug does not have the third rule: method override policy. The fourth rule of defined local variables is also dropped.
Command check is called for every keystroke to colorize input and to calculate prompt when used with Reline. Local variable check is too costly in remote debug session for this usage.

# IRB
irb(main):001> help = 1
=> 1
irb(main):002> help + 1
=> 2
irb(main):003> irb_help # help command
# Debug
(ruby) n = 1
1
(rdbg) n + 1 # this will be next command
Unknown option: + 1
(rdbg) p n + 1 # workaround
=> 2

`n = 1` `n += 1` will be a ruby expression, not a shorthand of `next` command.
@cloudbees-smart-tests

cloudbees-smart-tests Bot commented Jul 1, 2024 •

Copy link
Copy Markdown

✅ All Tests passed!

✖️no tests failed ✔️673 tests passed(1 flake)

@ko1

ko1 commented Jun 5, 2025

Copy link
Copy Markdown
Collaborator

I don't want to limit the command format in future, so close this PR.

@ko1 ko1 closed this Jun 5, 2025
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