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


marcandre (Marc-Andre Lafortune) wrote:
> First, I hope we can agree that `any(**{})` and `any(**Hash.new)` should have the exact same result (for any definition of `any`).

Of course :-)


> For me, writing `**hash` means "do as if I had written that hash inline".
> I.e. `any(**{k1: 1, k2: 2})` should have the exact same result as `any(k1: 1, k2: 2)`
> In the same way, `any(**{})` should have the exact same result as `any()`

What do you think about #15052?

```
def foo(opt = "opt", **hsh)
  p [opt, hsh]
end

foo({}, **{})  #=> expected: [{}, {}], actual: ["opt", {}]
```

According to your interpretation, `foo({}, **{})` is equal to `foo({})`, so the current result is correct.  We need to write `foo({}, {})` to get the expected result.
I added `**` explicitly to make sure that the second hash is a keyword hash, which made a bug.  This spoils the feature of double splat, I think.


> Advantages I see:
> a) Allows two ways to safely forward all arguments to another method:

Yes, good point.  If keyword arguments are separated from normal ones, we need to always forward three component: `def foo(*a, **h, &b); bar(*a, **h, &b); end`.  However, the code does not always work on the current semantics, as you said.  We need a migration path, or a coding style that works on both 2.X and 3.X, so this is a severe problem.

Surprisingly, in 2010, matz predicted this issue and proposed a new syntax for delegation in #3447: `def foo(...); bar(...); end`.  Unfortunately, it has not been accepted yet, though.


> Now even if the proposal was accepted and implemented, then `**{}` would still never create a positional argument! So I believe that you actually agree with me :-)

I'd like to agree with you, but also really like to fix #15052.  Do you find a good semantics of `**hash` to satisfy both this ticket and that one?

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

* 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>