Repository navigation
[fix] Keep parens on raise calls ending in an omitted hash value - #987
Merged
Merged
Conversation
`raise(Error, cause:)` was formatted as `raise Error, cause:`. Without parens, Ruby takes whatever follows an omitted value as that value, so the next line became the `cause:` argument, and a trailing modifier (`raise Error, cause: if x`) became a syntax error.
reese
approved these changes
Oct 25, 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.
raise(Error, cause:)is formatted asraise Error, cause:. Without parens, Ruby takes whatever follows an omitted hash value as that value, sobecomes
which raises with
cause: cleanup. With a modifier,raise(Error, cause:) if causebecomesraise Error, cause: if cause, which is a syntax error.The
raisebranch ofuse_parens_for_call_nodenow keeps the parens when the last argument is a keyword hash whose last value is omitted, the same way it already does for splats and argument forwarding. Otherraisecalls still lose their parens.fixtures/small/raise_omitted_hash_value_*covers both cases plus one beforeend. The fixture fails without the change. With it,cargo testpasses,cargo fmt --all -- --checkis clean,cargo clippyhas no warnings andscript/lints/lint_fixtures.shpasses.This isn't the #922 case that #986 fixes. There the call sits somewhere that needs a primary expression; here it's a plain statement. The case still reproduces on top of #986, and the two merge cleanly.
I found this by formatting ruby/spec and comparing Prism ASTs of the input and output with locations stripped. In
language/send_spec.rb, two consecutive-> { ... }.should.raise(NoMethodError, cause:)lines turned into output that no longer parses.