[#99868] [Ruby master Bug#17144] Tempfile.open { ... } does not unlink the file — eregontp@...
Issue #17144 has been reported by Eregon (Benoit Daloze).
15 messages
2020/09/03
[ruby-core:100039] [Ruby master Bug#17178] Procs with kw:def/**kw lose elements when called with a single Array
From:
merch-redmine@...
Date:
2020-09-18 19:18:19 UTC
List:
ruby-core #100039
Issue #17178 has been updated by jeremyevans0 (Jeremy Evans).
Eregon (Benoit Daloze) wrote:
> ```
> $ 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], {}]
> ```
Are we sure this is a bug, and not just the result of a different behavior of `proc{|a|}` `proc{|a,|}`, with keywords being treated like the latter (autosplatting) as a comma is used?
Keywords in procs have always caused autosplatting of the proc. With Ruby 3, we could change this if there were only a single argument and keywords, but it seems more like a new feature than a bug fix.
----------------------------------------
Bug #17178: Procs with kw:def/**kw lose elements when called with a single Array
https://bugs.ruby-lang.org/issues/17178#change-87589
* Author: Eregon (Benoit Daloze)
* Status: Open
* Priority: Normal
* ruby -v: ruby 3.0.0dev (2020-09-18T09:12:58Z master e1cca08a6d) [x86_64-linux]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN
----------------------------------------
```
$ 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], {}]
```
--
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>