Project

General

Profile

Bug #10293

splatting an empty hash in a method invocation sends an argument to the method (should send nothing)

Added by rits (First Last) about 5 years ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.1.3p242 (2014-09-19 revision 47630) [x86_64-linux]
[ruby-core:65263]

Description

irb(main):001:0> def foo; end; foo **{}
ArgumentError: wrong number of arguments (1 for 0)

note that splatting an empty array results in no arguments

this behavior is particularly problematic with send (dispatching to different methods)

send method_name, *possibly_empty_arg_list, **possibly_empty_keyarg_hash

one should not have to do

if possibly_empty_keyarg_hash.empty?
receiver.send method_name, *possibly_empty_arg_list
else

receiver.send method_name, *possibly_empty_arg_list, **possibly_empty_keyarg_hash
end

or

possibly_empty_arg_list << possibly_empty_keyarg_hash unless possibly_empty_keyarg_hash.empty?
receiver.send method_name, *possibly_empty_arg_list


Related issues

Related to Ruby master - Feature #14183: "Real" keyword argumentClosedActions

History

Updated by nagachika (Tomoyuki Chikanaga) about 5 years ago

  • Category set to core
  • Status changed from Open to Assigned
  • Assignee set to nobu (Nobuyoshi Nakada)
  • Target version set to 2.2.0
  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: UNKNOWN, 2.1: REQUIRED

Updated by rits (First Last) about 5 years ago

https://bugs.ruby-lang.org/issues/9291 is somewhat related
foo(**nil) should not raise since foo(*nil) does not and it's the more useful behavior

#3

Updated by naruse (Yui NARUSE) almost 2 years ago

  • Target version deleted (2.2.0)
#4

Updated by jeremyevans0 (Jeremy Evans) 4 months ago

Updated by jeremyevans0 (Jeremy Evans) 3 months ago

  • Status changed from Assigned to Closed

With the acceptance of #14183, double splatting an empty hash no longer sends an empty positional hash to the method.

Also available in: Atom PDF