Skip to content

Conversation

@Earlopain
Copy link
Contributor

For these special cases, there exists no optional argument type. Since a endless method is started with =, there was ambiguity here. We have to simply reject these in all cases.

This adds a new error for the following reason:

  • def foo arg = nil is interpreted as a normal method call with optional arg without matching end
  • def foo *arg = nil; end is interpreted as a endless method call that has body nil with extraneous end

def foo *arg = nil is somewhere inbetween and I don't know how to otherwise indicate the error.
Now the second case above also shows the newly added error message.

Fixes [Bug #21623]

…e a endless method is started with `=`, there was ambiguity here. We have to simply reject these in all cases.

This adds a new error for the following reason:
* `def foo arg = nil` is interpreted as a normal method call with optional `arg` without matching `end`
* `def foo *arg = nil; end` is interpreted as a endless method call that has body `nil` with extraneous `end`

`def foo *arg = nil` is somewhere inbetween and I don't know how to otherwise indicate the error.
Now the second case above also shows the newly added error message.

Fixes [Bug #21623]
Copy link
Collaborator

@kddnewton kddnewton left a comment

Choose a reason for hiding this comment

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

Yeah, looks good

@kddnewton kddnewton merged commit 022d6d0 into ruby:main Oct 8, 2025
60 checks passed
@tompng
Copy link
Member

tompng commented Oct 8, 2025

I'm not sure if it's related to this fix, perhaps a separate issue, but def foo a, (b) = 1 is wrongly accepted.

Earlopain added a commit to Earlopain/prism that referenced this pull request Nov 1, 2025
Fixes [#Bug 21660], followup to ruby#3674
Earlopain added a commit to Earlopain/prism that referenced this pull request Nov 1, 2025
Fixes [#Bug 21660], followup to ruby#3674

Co-Authored-By: tomoya ishida <[email protected]>
matzbot pushed a commit to ruby/ruby that referenced this pull request Nov 6, 2025
Fixes [#Bug 21660], followup to ruby/prism#3674

ruby/prism@fb445a49e5

Co-Authored-By: tomoya ishida <[email protected]>
stevenjohnstone pushed a commit to stevenjohnstone/prism that referenced this pull request Nov 10, 2025
Fixes [#Bug 21660], followup to ruby#3674

Co-Authored-By: tomoya ishida <[email protected]>
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.

3 participants