Fix RuntimeError on () as a method arg or hash splat value#445
Merged
mame merged 1 commit intoruby:masterfrom Apr 28, 2026
Merged
Conversation
`CallBaseNode` and `HashNode` used `DummyNilNode` as a sentinel for anonymous rest forwarding (bare `*`) and anonymous keyword splat forwarding (bare `**`), checking via `is_a?(DummyNilNode)` at install time. Once empty parentheses `()` started producing `DummyNilNode` (via the parentheses_node unwrap in AST.create_node), passing `()` as a method argument or hash splat value was misinterpreted as anonymous forwarding, raising `RuntimeError: *anonymous_rest` or `**anonymous_keyword` from `LocalEnv#get_var`. Use plain `nil` as the placeholder for those forwarding cases instead, so `DummyNilNode` is reserved for actual nil-valued expressions. Also extend `scenario/misc/parens.rb` with cases where empty parens appear as an array element, an if condition, a method argument, a splatted argument, and a hash double-splat value. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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.
Summary
Follow-up to #441. After empty parentheses
()started producing aDummyNilNode, several call/hash sites began misinterpreting()as anonymous-forwarding syntax, raisingRuntimeError: *anonymous_restor**anonymous_keywordfromLocalEnv#get_var.Reproducers (all crash on current master):
Root cause
CallBaseNodeandHashNodewere overloadingDummyNilNodeas a sentinel for bare*/**forwarding. The placeholder created at parse time when the raw arg/value wasnil(the anonymous-forwarding case) was later detected withis_a?(DummyNilNode)at install time. Once()also became aDummyNilNode, the two cases collided.Reported by @sinsoku as the "separate issue" note in #441.
Fix
Use a plain
nilas the forwarding-placeholder in@positional_argsand@vals, and checkarg.nil?/val.nil?at install time.DummyNilNodeis then reserved for actual nil-valued expressions like(), with no semantic overlap.Test plan
scenario/misc/parens.rbextended with the new cases (also covers @sinsoku's other suggestions:[()]andif (); 1; end)rake testpasses (425 tests, 817 assertions)scenario/args/anonymous_rest.rb) still passes