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 #1

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

  • Status changed from Open to Closed

Applied in changeset git|d05f04d27dd86c67e4a8dfff4392f806cf577bdf.


Fixed defined? against protected method call

Protected methods are restricted to be called according to the
class/module in where it is defined, not the actual receiver's
class. [Bug #16931]

Updated by nagachika (Tomoyuki Chikanaga) over 3 years ago

I cherry-pick'ed the following commits before backporting d05f04d27dd86c67e4a8dfff4392f806cf577bdf.
de9d6a7a8cb0929e0b4cf0a3120971c7b8ee8927
da5bd0047d6c961105da210c69d4c88421324b70
ce91c5615ca96f357519043181fb5b76b57ee223
c53aebb1d2eb5afbb18f9b3db9f9c956a463a4e1

Updated by nagachika (Tomoyuki Chikanaga) over 3 years ago

  • Backport changed from 2.5: REQUIRED, 2.6: REQUIRED, 2.7: REQUIRED to 2.5: REQUIRED, 2.6: REQUIRED, 2.7: DONE

ruby_2_7 23d130a9ddcaf766d6ce309f8518b434a2537fc1 merged revision(s) d05f04d27dd86c67e4a8dfff4392f806cf577bdf.

Updated by usa (Usaku NAKAMURA) about 3 years ago

  • Backport changed from 2.5: REQUIRED, 2.6: REQUIRED, 2.7: DONE to 2.5: REQUIRED, 2.6: DONE, 2.7: DONE

ruby_2_6 r67920 merged revision(s) de9d6a7a8cb0929e0b4cf0a3120971c7b8ee8927,da5bd0047d6c961105da210c69d4c88421324b70,ce91c5615ca96f357519043181fb5b76b57ee223,c53aebb1d2eb5afbb18f9b3db9f9c956a463a4e1,d05f04d27dd86c67e4a8dfff4392f806cf577bdf.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0