You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Data#to_h passes one Array to the block instead of the key and the value #10066
With a block, Data#to_h yields one Array [key, value] to the block, not two values. A block with two parameters, { |key, value| }, still works because a proc spreads the Array, and so do { |*args| }, &method(...) with a method that takes two arguments, and a lambda that takes two arguments. A block with one parameter gets the wrong argument: { |key| }, { it } and { _1 } get the whole Array instead of the key, and a lambda that takes one argument is called with the Array instead of raising ArgumentError. The docs show to_h {|name, value| ... } -> hash (Data#to_h), and CRuby yields two values. Struct#to_h with a block already behaves like CRuby on JRuby.
JRuby 10.1.3.0 (jruby 10.1.3.0 (4.0.9) 2026-11-05 3db52d02f9 OpenJDK 64-Bit Server VM 21.0.13+9-LTS on 21.0.13+9-LTS +indy +jit [aarch64-linux]) and a build of master (54dd973) print the same.
RubyData.to_h yields with block.yieldSpecific(context, k, v) (RubyData.java#L190; on master RubyData.java#L199), which passes the two values as one Array to a block with a single parameter. CRuby's Data#to_h is rb_struct_to_h (struct.c#L2047), which calls rb_yield_values(2, k, v) (struct.c#L1096). RubyStruct#to_h already uses block.yieldValues, and the same call in RubyData.to_h should match CRuby.
ruby/spec's "passes to a block each pair's key and value as separate arguments" checks only { |k, v| } and { |*args| }, which get the same values either way, so it passes on JRuby (to_h_spec.rb#L16-L25).
Found while comparing JRuby with CRuby on ruby/spec-based checks.
Activity
headius commentedon Nov 17, 2026
Fixed by #10070.