Skip to content

Yield the key and value as two values to the Data#to_h block - #10070

Merged
headius merged 1 commit into
jruby:jruby-10.0from
taxor03:fix-data-to-h-block-10.0
Nov 17, 2026
Merged

headius merged 1 commit into
jruby:jruby-10.0from
taxor03:fix-data-to-h-block-10.0

Conversation

@taxor03

@taxor03 taxor03 commented Nov 13, 2026

Copy link
Copy Markdown
Contributor

Fixes #10066.

Data#to_h with a block yielded with block.yieldSpecific(context, k, v), so a block with one parameter got the Array [key, value]. It now yields the two values with block.yieldValues, like RubyStruct#to_h and like the rb_yield_values(2, k, v) call in CRuby's rb_struct_to_h, which CRuby also uses for Data#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:

block before after (same as CRuby 4.0.9 and 3.4.12)
{ |key| }, { it }, { _1 } [key, value] key
&->(a) { } called with [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 with spec/ruby/core/data (also with -Xjit.threshold=0 and -X-C), test/mri/ruby/test_data.rb and 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.

@headius headius left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice simple fix.

@headius
headius merged commit 769c37f into jruby:jruby-10.0 Nov 17, 2026
127 checks passed
@headius headius added this to the JRuby 10.0.9.0 milestone Nov 17, 2026
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