From: mame@... Date: 2019-03-14T05:06:41+00:00 Subject: [ruby-core:91825] [Ruby trunk Bug#10856] Splat with empty keyword args gives unexpected results Issue #10856 has been updated by mame (Yusuke Endoh). Target version changed from 2.5 to 2.7 Status changed from Closed to Assigned marcandre (Marc-Andre Lafortune) wrote: > This is not actually fixed. > > ``` > def foo > puts "OK" > end > > options = {} > foo(**options) # => OK (In 2.5.0preview1) > args = [] > foo(*args, **options) # => ArgumentError: wrong number of arguments (given 1, expected 0) > ``` > > The second call should also output "Ok". > > Hopefully Nobu can crack this before 2.5.0 This is not completely fixed yet: ``` $ ruby -v ruby 2.6.0p0 (2018-12-25 revision 66547) [x86_64-linux] $ ruby -e 'def foo; end; options = {}; args = []; foo(*args, **options)' $ ruby -e 'def foo(z); end; options = {}; args = []; foo(*args, 1, **options)' Traceback (most recent call last): 1: from -e:1:in `
' -e:1:in `foo': wrong number of arguments (given 2, expected 1) (ArgumentError) ``` I go for the exception. `opt = {}; foo(**option)` should consistently pass an empty hash instead of ignoring it. It is not intuitive, but it IS the current spec of keyword argument. This is a design flaw in the current spec. I believe that it must be fixed by complete separation between keyword arguments and positional arguments (#14183). ---------------------------------------- Bug #10856: Splat with empty keyword args gives unexpected results https://bugs.ruby-lang.org/issues/10856#change-77095 * Author: seantheprogrammer (Sean Griffin) * Status: Assigned * Priority: Normal * Assignee: nobu (Nobuyoshi Nakada) * Target version: 2.7 * ruby -v: ruby 2.2.0p0 (2014-12-25 revision 49005) [x86_64-darwin13] * Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN ---------------------------------------- When keyword args are passed to a method with splat, and there are no keyword args, an empty hash is sent. I would expect no argument to be given, same as splat with an empty array. For example: ```ruby def foo end foo(**{}) ``` This causes an argument error, as an empty hash is passed. I would expect the same behavior as ```ruby def foo end foo(*[]) ``` -- https://bugs.ruby-lang.org/ Unsubscribe: