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

From: mame@...
Date: 2019-11-26 07:32:47 UTC
List: ruby-core #95952
Issue #16371 has been updated by mame (Yusuke Endoh).


`**` operator is for keyword arguments, and in Ruby 2.6, non-symbol key is not allowed in keyword arguments.  So in principle, `{x: 'x', **{'b' => 'b'}}` should raise an exception.

Because of the spec change of keyword arguments (#14183), non-symbol key is allowed in Ruby 2.7, and all shown cases work without exception.

Do you want the case to raise an exception in Ruby 2.6?

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

* 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 wierd behavior of a 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)
```

But when I do that implicitly it works:
```
{x: 'x', **{'b' => 'b'}} 
#=> {:x=>"x", "b"=>"b"}
```

In 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 that example or give advice? ( maybe I incorrectly use it? ) 



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

In This Thread

Prev Next