Project

General

Profile

Actions

Bug #17178

closed

Procs with kw:def/**kw lose elements when called with a single Array

Added by Eregon (Benoit Daloze) over 3 years ago. Updated over 3 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 3.0.0dev (2020-09-18T09:12:58Z master e1cca08a6d) [x86_64-linux]
[ruby-core:100037]

Description

$ ruby -ve '{a: 1}.each_pair { |a, kw: :def| p [a,kw] }'
ruby 3.0.0dev (2020-09-18T09:12:58Z master e1cca08a6d) [x86_64-linux]
[:a, :def] # bug, should be [[1, 2], :def]

$ ruby -ve '{a: 1}.each_pair { |a, **kw| p [a,kw] }' 
ruby 3.0.0dev (2020-09-18T09:12:58Z master e1cca08a6d) [x86_64-linux]
[:a, {}] # bug, should be [[1, 2], {}]

So the value of the key-value pair is lost and not assigned to any argument.

This seems a general problem of Proc, not just #each_pair:

$ ruby -e 'proc { |a, kw: :def| p [a,kw] }.call(1,2)'  
[1, :def] # understandable
$ ruby -e 'proc { |a, kw: :def| p [a,kw] }.call([1,2])'
[1, :def] # bug, should be [[1, 2], :def]


$ ruby -e 'proc { |a, **kw| p [a,kw] }.call(1,2)'     
[1, {}] # understandable
$ ruby -e 'proc { |a, **kw| p [a,kw] }.call([1,2])'
[1, {}] # bug, should be [[1, 2], {}]
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0