Repository navigation
Coerce a non-Hash keyword splat (**obj) via #to_hash - #504
Merged
Merged
Conversation
A `**operand` keyword splat whose operand was not already a Hash raised
TypeError unconditionally, so `f(**obj)` for an object with #to_hash — and
`f(**nil)` — failed where MRI accepts them. The OpHashMerge handler now
mirrors MRI's implicit keyword-splat conversion: nil contributes nothing
(`f(**nil)` is `f()`), any other non-Hash operand is coerced with #to_hash,
and a value with no #to_hash ("no implicit conversion of X into Hash") or
whose #to_hash yields a non-Hash ("can't convert X to Hash (X#to_hash
gives Y)") raises TypeError with MRI's message. A Hash operand and a
hash-literal `**` stay on the unchanged fast path.
Verified against MRI Ruby 4.0.6, including the `Encoding::Converter.new(…,
**opts)` spec whose options carry #to_hash. ruby/spec ratchet FLOOR
16305 -> 16335 (measured total 16391).
Co-Authored-By: Claude Opus 4.8 <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.
A
**operandkeyword splat whose operand was not already a Hash raisedTypeErrorunconditionally, sof(**obj)for an object with#to_hash— andf(**nil)— failed where MRI accepts them.The
OpHashMergehandler now mirrors MRI's implicit keyword-splat conversion:nilcontributes nothing (f(**nil)≡f());#to_hash;#to_hashraisesno implicit conversion of X into Hash;#to_hashyields a non-Hash raisescan't convert X to Hash (X#to_hash gives Y).A Hash operand and a hash-literal
**stay on the unchanged fast path.Verified byte-for-byte against MRI Ruby 4.0.6, including the
Encoding::Converter.new(…, **opts)spec whose options object carries#to_hash.Conformance: ruby/spec ratchet FLOOR 16315 → 16335 (measured total 16391).
go test ./...green, native +wasip1/wasmbuild, gofmt clean, 100% coverage of the new branches.🤖 Generated with Claude Code