Jruby: Double splat with empty parameters fails to find child's empty arity method

Created on 1 Jun 2020  路  4Comments  路  Source: jruby/jruby

Environment Information
jruby 9.2.11.1 (2.5.7) 2020-03-25 b1f55b1a40 OpenJDK 64-Bit Server VM 25.252-b09 on 1.8.0_252-b09 [darwin-x86_64]

Catalina 10.15.4

Expected Behavior

  • Under MRI 2.5.8 the script works as expected with "hello there" being printed
class Parent
  def call(**args)
    execute(**args)
  end

  def execute(**_args)
    fail NotImplementedError
  end
end

class Child < Parent
  def execute
    puts 'hello there'
  end
end

Child.new.call

Actual Behavior

  • The error ArgumentError: wrong number of arguments (given 1, expected 0) is thrown.

All 4 comments

Looking at the arity of each, the numbers are consistent between MRI and JRuby.

parent = Parent.new
child = Child.new

parent.method(:execute).arity # => returns -1
child.method(:execute).arity # => returns 0

Reduced repro to:

def foo
  puts "A"
end

foo(**{})

The base problem is kwargs are not necessarily perceived as an argument if it has nothing in it. We assume if we passed an empty kwrest it must be an argument.

This is basically #6564 but I will leave open and resolve both since they report the problem differently enough that depending on how people search for this issue they will find one or the other.

Fixed in 2b7236c52c6ac037d5db72f8d9e04c0bcc71a401

Was this page helpful?
0 / 5 - 0 ratings