[ruby-core:105644] [Ruby master Feature#15973] Let Kernel#lambda always return a lambda
From:
"Eregon (Benoit Daloze)" <noreply@...>
Date:
2021-10-15 12:35:09 UTC
List:
ruby-core #105644
Issue #15973 has been updated by Eregon (Benoit Daloze).
@jeremyevans added a test for this in https://github.com/ruby/ruby/commit/2188d6d160d3ba82432c87277310a4d417e136d5#diff-8b146f8f5073c5ee6526a128c3e9c05ae7a52d2cd496f601351470137f2a87a0
but it was removed by @nobu in https://github.com/ruby/ruby/commit/996af2ce086249e904b2ce95ab2fcd1de7d757be#diff-8b146f8f5073c5ee6526a128c3e9c05ae7a52d2cd496f601351470137f2a87a0
And also this no longer warns, which sounds like a bug due to removing that test:
```
$ ruby -v -w -e 'p Warning[:deprecated]; p lambda(&:symbol)'
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]
true
#<Proc:0x0000000001b07a38(&:symbol) (lambda)>
```
I guess maybe expected since Symbol#to_proc#lambda? is true (was false in 2.7)
And in that logic `ruby -v -w -e 'p Warning[:deprecated]; p lambda(&lambda{})'` also doesn't warn.
This does warn as intended though, and we'll add a spec for it:
```
$ ruby -v -w -e 'p Warning[:deprecated]; p lambda(&proc{})'
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]
true
-e:1: warning: lambda without a literal block is deprecated; use the proc without lambda instead
#<Proc:0x00000000020dfcf8 -e:1>
```
Found from https://github.com/oracle/truffleruby/pull/2500
----------------------------------------
Feature #15973: Let Kernel#lambda always return a lambda
https://bugs.ruby-lang.org/issues/15973#change-94134
* Author: alanwu (Alan Wu)
* Status: Closed
* Priority: Normal
* Assignee: matz (Yukihiro Matsumoto)
* Target version: 3.0
----------------------------------------
When Kernel#lambda receives a Proc that is not a lambda,
it returns it without modification. l propose to change `Kernel#lambda`
so it always returns a lambda.
Calling a method called lambda and having it do nothing in effect is
not very intuitive.
https://github.com/ruby/ruby/pull/2262
Judging from marcandre's investigation here: https://bugs.ruby-lang.org/issues/15620#note-1,
changing the behavior should not cause much breakage, if any.
This also happens to fix [Bug #15620]
--
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>