Skip to content

Cruby/Jruby behavior difference with block keyword arguments #6540

@jhottenstein

Description

@jhottenstein

Environment Information

  • jruby 9.2.13.0 (2.5.7) 2020-08-03 9a89c94 Java HotSpot(TM) 64-Bit Server VM 25.271-b09 on 1.8.0_271-b09 +jit [darwin-x86_64]
  • Darwin mac.local 20.2.0 Darwin Kernel Version 20.2.0: Wed Dec 2 20:39:59 PST 2020; root:xnu-7195.60.75~1/RELEASE_X86_64 x86_64

Other relevant info you may wish to add:

  • ruby2_keywords must be used - otherwise cruby returns the same error

Expected Behavior
I extracted the following behavior from a test failure when writing rspec/rspec-mocks#1407
The below code works in every version of cruby tested by the rspec build(1.8.7-3.0.0) and jruby 1.7. It failed for jruby 9.2.13.0 and 9.1.17.0

klass = Class.new do
  def a(*args, &block)
    block.call(*args)
  end

  ruby2_keywords(:a) if respond_to?(:ruby2_keywords, true)
end

klass.new.a(kw: :arg) { |kw:| kw }
=> :arg
klass.new.a(:positional, kw: :arg) { |kw:| kw }
=> :arg

Actual Behavior

klass.new.a(kw: :arg) { |kw:| kw }
=> :arg
klass.new.a(:positional, kw: :arg) { |kw:| kw }
Traceback (most recent call last):
        8: from /Users/jhottenstein/.rbenv/versions/jruby-9.2.13.0/bin/irb:13:in `<main>'
        7: from org/jruby/RubyKernel.java:1189:in `catch'
        6: from org/jruby/RubyKernel.java:1189:in `catch'
        5: from org/jruby/RubyKernel.java:1442:in `loop'
        4: from org/jruby/RubyKernel.java:1048:in `eval'
        3: from (irb):10:in `evaluate'
        2: from (irb):3:in `a'
        1: from (irb):3:in `block in evaluate'
ArgumentError (missing keyword: kw)

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