Project

General

Profile

Actions

Feature #17361

closed

lambda(&block) does not warn with lazy proc allocation

Added by znz (Kazuhiro NISHIYAMA) over 3 years ago. Updated over 3 years ago.

Status:
Closed
Target version:
-
[ruby-core:101209]

Description

In NEWS,

        * Kernel#lambda now warns if called without a literal block.
          [[Feature #15973]]

But the following code from https://docs.ruby-lang.org/ja/latest/method/Kernel/m/lambda.html (https://github.com/rurema/doctree/blob/495868c466c97c9bcca28d64d6ce0d68350de3e2/refm/api/src/_builtin/functions#L2436-L2441) does not warn.

def foo &block
  lambda(&block)
end

it = foo{p 12}
it.call #=> 12

Once block assign to a local variable, it warns.

def foo &block
  b = block
  lambda(&b)
end

it = foo{p 12}
it.call #=> 12

Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #15973: Let Kernel#lambda always return a lambdaClosedmatz (Yukihiro Matsumoto)Actions
Actions #1

Updated by znz (Kazuhiro NISHIYAMA) over 3 years ago

  • Related to Feature #15973: Let Kernel#lambda always return a lambda added
Actions #2

Updated by ko1 (Koichi Sasada) over 3 years ago

  • Assignee set to ko1 (Koichi Sasada)
Actions #3

Updated by ko1 (Koichi Sasada) over 3 years ago

  • Status changed from Open to Closed

Applied in changeset git|b53ccb9c69abd24e3bdad66cbe4c7e7480eaef16.


show deprecation warning correctly for lambda(&b)

lambda(&b) where b is given block of method (like: def foo(&b))
should warn correctly.
[Feature #17361]

Also labmda(&labmda_block) or lambda(&:to_s) (Symbol#to_proc)
should not warn (but I'm not sure who cares about it).

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0