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
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
ArgumentError: wrong number of arguments (given 1, expected 0) is thrown.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