Skip to content

Inconsistency with block parameter default value #9208

@katafrakt

Description

@katafrakt

We encountered a bug in dry-types where JRuby does not behave the same way as MRI. I spent some time trying to reproduce it in non-dry-types environment and I think I have a minimal reproducible example now (although still quite convoluted):

class Inner
  def call(input)
    result = input.each_with_object([]) { |x, arr| arr << x * 2 }
    yield(result)
  end
end

class Outer
  def initialize(inner) = @inner = inner

  def call(input, &block)
    @inner.call(input) { |output = input| block.call(output) }
  end
end

input = [1, 2, 3]
p Outer.new(Inner.new).call(input) { |x| x }

On Ruby 3.4.1 it returns [2, 4, 6], while in JRuby it just returns 2.

Environment Information

Provide at least:

  • JRuby version: 10.0.2.0
  • Operating system and platform : Linux 6.18.6-arch1-1

Expected Behavior

  • JRuby and MRI behave the same way, returning [2, 4, 6].

Actual Behavior

  • JRuby returns different data structure.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions