[ruby-core:95972] [Ruby master Bug#16371] Inconsistent usage of Double splat operator

[email protected]
Newsgroups gmane.comp.lang.ruby.core
Message-ID <redmine.journal-82807.20191127030611.20578086671a7fb4@ruby-lang.org>
Issue #16371 has been updated by mame (Yusuke Endoh).


matz, the following is the current behaviors.  Do you mean which should be fixed?

(1) 2.7, via variable

```
b = {"b" => "b"}; p({x: "x", **b}) #=> current behavior: {:x=>"x", "b"=>"b"}
```

(2) 2.6, via variable

```
b = {"b" => "b"}; p({x: "x", **b}) #=> current behavior: hash key "b" is not a Symbol (TypeError)
```

(3) 2.7, with literal

```
p({x: "x", **{"b" => "b"}}) #=> current behavior: {:x=>"x", "b"=>"b"}
```

(4) 2.6, with literal

```
p({x: "x", **{"b" => "b"}}) #=> current behavior: {:x=>"x", "b"=>"b"}
```

----------------------------------------
Bug #16371: Inconsistent usage of Double splat operator
https://bugs.ruby-lang.org/issues/16371#change-82807

* Author: dmytro.vasin (Dmytro Vasin)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 2.6.0
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
Here is an issue with a weird behavior of ruby double splat operator: 

```
a = {a: 'a'}
b = {'b' => 'b'}

{x: 'x', **a}
#=> {:x=>"x", :a=>"a"}

{x: 'x', **b}
#=> TypeError (hash key "b" is not a Symbol)
```

When I do that implicitly, it works:

```
{x: 'x', **{'b' => 'b'}} 
#=> {:x=>"x", "b"=>"b"}
```

At the same time:

```
{**{'b' => 'b'}}
# TypeError (hash key "b" is not a Symbol)
```

From my point of view, it definitely works inconsistently.

Could you help with this example or give an advice? (maybe I used it incorrectly?)



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

Unsubscribe: <mailto:[email protected]?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.