Issue #15078 has been updated by mame (Yusuke Endoh).


It is not so trivial what it should be.  If you look at only `foo(**{}) #=> [{}]` itself, it might be non-intuitive, indeed.  However, IMO, this is a consequence of the current weird spec of keyword arguments (a keyword hash is passed as a normal last argument).  Unless the spec itself changes, it would be more consistent for `foo(**{})` to return `[{}]`.

See the following example:

```
def foo(*args)
  p args
end
foo(**{k1: 1, k2: 2, k3: 3}) #=> [{:k1=>1, :k2=>2, :k3=>3}]
foo(**{k1: 1, k2: 2})        #=> [{:k1=>1, :k2=>2}]
foo(**{k1: 1})               #=> [{:k1=>1}]
foo(**{})                    #=> [] # surprising, should be [{}]
```

The number of arguments changes depending upon the value.  I think such a behavior is error-prone.  It should not occur, unless the caller uses `foo(*ary)` explicitly.  People will not expect the number change in `foo(**hsh)`.

In fact, the fix you proposed will make it difficult to test the following program:

```
def f2(h)
end

def f1(foo, bar)
  h = {}
  h[:foo] = :foo if foo
  h[:bar] = :bar if bar
  f2(**h)
end
```

It will break only when `f1(false, false)`.  

Do you think it is bad to accept a keyword hash (`f2(**h)`) as a normal parameter (`def f2(h)`)?  Yes, I agree.  So I'm proposing #14183.  If keyword arguments are split from normal arguments, we can fix this issue gracefully: we can always ignore `**{}` safely.  If the current weird spec is kept, I don't think it is a good idea to "fix" this ad-hocly just because it might be non-intuitive.

----------------------------------------
Bug #15078: Hash splat of empty hash should not create a positional argument.
https://bugs.ruby-lang.org/issues/15078#change-73918

* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: nobu (Nobuyoshi Nakada)
* Target version: 
* ruby -v: ruby 2.6.0dev (2018-08-27 trunk 64545) [x86_64-darwin15]
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
Looks like #10856 is not completely fixed, but I can't reopen it

```
def foo(*args); args; end
foo(**{}) # => []
foo(**Hash.new) # => [{}], should be []
```



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>