Skip to content

[fix] Keep parens on raise calls ending in an omitted hash value - #987

Merged
reese merged 1 commit into
fables-tales:trunkfrom
wleeaf:raise-omitted-hash-value
Oct 25, 2026
Merged

reese merged 1 commit into
fables-tales:trunkfrom
wleeaf:raise-omitted-hash-value

Conversation

@wleeaf

@wleeaf wleeaf commented Oct 25, 2026

Copy link
Copy Markdown
Contributor

raise(Error, cause:) is formatted as raise Error, cause:. Without parens, Ruby takes whatever follows an omitted hash value as that value, so

def retry_with(cause)
  raise(RetryError, cause:)
  cleanup
end

becomes

def retry_with(cause)
  raise RetryError, cause:
  cleanup
end

which raises with cause: cleanup. With a modifier, raise(Error, cause:) if cause becomes raise Error, cause: if cause, which is a syntax error.

The raise branch of use_parens_for_call_node now 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. Other raise calls still lose their parens.

fixtures/small/raise_omitted_hash_value_* covers both cases plus one before end. The fixture fails without the change. With it, cargo test passes, cargo fmt --all -- --check is clean, cargo clippy has no warnings and script/lints/lint_fixtures.sh passes.

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.

`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
reese merged commit 884b9fd into fables-tales:trunk Oct 25, 2026
8 checks passed
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