[ruby-core:95405] [Ruby master Bug#15052] must not optimize `foo(**{})` out

From: merch-redmine@...
Date: 2019-10-17 22:05:08 UTC
List: ruby-core #95405
Issue #15052 has been updated by jeremyevans0 (Jeremy Evans).

Status changed from Open to Closed

Fixed by commit:1d5066efb08cbb328ba528a5f8be1708584b659f.

----------------------------------------
Bug #15052: must not optimize `foo(**{})` out
https://bugs.ruby-lang.org/issues/15052#change-82136

* Author: mame (Yusuke Endoh)
* Status: Closed
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
A keyword rest argument with empty hash, `**{}`, is removed during parsing phase.  However, under the current spec of keyword parameters, this leads to a problem:

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

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

`foo({}, **{})` is obviously expected to pass the first `{}` to `opt`, and the second `**{}` to `**hsh`.  However, `**{}` is removed at parsing phase, sp the first `{}` is considered as a keyword rest argument, which causes the above strange result.

So, we cannot optimize `**{}` out, unless keyword argument is separated from normal arguments #14183.  (The current spec is really intractable not only for Ruby users but also for Ruby developers!)

---Files--------------------------------
do-not-optimize-keyword-argument-with-empty-hash.patch (717 Bytes)


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

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

In This Thread

Prev Next