Project

General

Profile

Bug #15138

non-symbol keyword in double splat, such as **{2 => 3}, raises TypeError or not

Added by akr (Akira Tanaka) about 1 year ago. Updated 2 months ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:89074]

Description

I found that non-symbol keyword in double splat, such as **{2 => 3},
raises TypeError in a situation and doesn't raise in another situation:

% ./ruby -ve '
def m(*a) p a end
m(k: 1, **{2 => 3}) # [{:k=>1, 2=>3}]
m(**{4 => 5}) # hash key 4 is not a Symbol (TypeError)
'
ruby 2.6.0dev (2018-09-18 trunk 64776) [x86_64-linux]
[{:k=>1, 2=>3}]
Traceback (most recent call last):
-e:4:in `<main>': hash key 4 is not a Symbol (TypeError)

It seems another keyword argument, k: 0 here, prevent TypeError.
I think this behavior is not intentional.

History

Updated by jeremyevans0 (Jeremy Evans) 2 months ago

  • Status changed from Open to Closed

With the acceptance of #14183, non-symbols are allowed in keyword hash splats:

m(k: 1, **{2 => 3}) 
# [{:k=>1, 2=>3}]

m(**{4 => 5}) 
# [{4=>5}]

Also available in: Atom PDF