[fix] Always render parens for capitalized methods with receivers#870
Merged
Conversation
reese
commented
May 9, 2026
|
|
||
| # But ConstantReadNodes must disambiguate blocks | ||
| Test::Case | ||
| Test::Case() |
Collaborator
Author
There was a problem hiding this comment.
I just tested every combination of with/without parens and with/without brace or do/end blocks, but please double-check that all of these are what we expect. I think they're right, but I'd like to make sure these cover every possible case
froydnj
approved these changes
May 12, 2026
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.
Closes #869
TL;DR for callers where the receiver is a
ConstantReadNode(e.g.Foo::Bar() { }), parentheses are required for Prism to parse that call, so this adds a receiver check to ensure they're always left behind in this case.Capitalized methods are a bit of a strange creature when it comes to how the parser handles them. On their own, they're essentially fine: a plane ol'
Foois a constant, andFoo(),Foo { },Foo do; endorFoo() { }are allCallNodes. In all of those cases, Prism understands them to be calls as soon as it sees the parens or the block delimiters, so we can elide parens if there's nothing in them, as long as a block is present.However, this isn't the same for capitalized methods where the receiver is a
ConstantReadNode. In those cases, once Prism gets through the method name (e.g.Foo::Bar), it's ambiguous as to whether it's a constant or a call. For whatever reason, brace blocks actually do work fine here, andFoo::Bar { }is a totally valid call in Prism (not in parse.y!), butFoo::Bar do; endis not. For these, it's required that capitalized methods in constant reads use parens to force the parser to understand them as method calls, soFoo::Bar() do; endworks.Note: for the sake of consistency, I chose to just check for any receiver and not care about the block type. In theory, we could still elide parens for block braces if we wanted to, but (1) I don't think older parser versions accept that, and (2) if we're required to have parens some of the time for this type of caller, I think it makes sense to just keep them all of the time.