Project

General

Profile

Actions

Bug #16931

closed

`defined?` against a protected method call on an inherited instance returns wrong `nil`

Added by nobu (Nobuyoshi Nakada) almost 4 years ago. Updated about 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
2.8.0dev (2020-06-02T08:21:03Z master 56ca006784)
[ruby-core:98624]

Description

The following code shows :callable first, but nil next, since 1.9.
If the method is callable, defined? expression has to return truthy value.

class A
  def foo
    :callable
  end
  protected :foo
  def t(x)
    x.foo
  end
  def q(x)
    defined?(x.foo)
  end
end
class B<A
end
a = A.new
b = B.new
p a.t(b) #=> :callable
p a.q(b) #=> nil
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0