Repository navigation
Yield the key and value as two values to the Data#to_h block - #10070
Merged
Merged
Conversation
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.
Fixes #10066.
Data#to_hwith a block yielded withblock.yieldSpecific(context, k, v), so a block with one parameter got the Array[key, value]. It now yields the two values withblock.yieldValues, likeRubyStruct#to_hand like therb_yield_values(2, k, v)call in CRuby'srb_struct_to_h, which CRuby also uses forData#to_h.Blocks with
|key, value|or|*args|,&method(...)with a two-argument method, and two-argument lambdas work as before. Blocks with one parameter now get what CRuby gives them:{ |key| },{ it },{ _1 }[key, value]key&->(a) { }[key, value]ArgumentError(given 2, expected 1)This adds two examples to
spec/ruby/core/data/to_h_spec.rb, one for a one-parameter block and one for a one-argument lambda. They fail before this change and pass after it, and pass on CRuby 4.0.9 and 3.4.12. Tested withspec/ruby/core/data(also with-Xjit.threshold=0and-X-C),test/mri/ruby/test_data.rband the fast RubySpec suite. No new failures.The commit cherry-picks cleanly onto master, where the same line is at RubyData.java#L199, and the new examples pass there with the default parser and with
-Xparser.prism.