Project

General

Profile

Actions

Bug #14407

closed

defined? still returning true for top-level constant when referenced with scope

Added by grzuy (Gonzalo Rodriguez) almost 7 years ago. Updated almost 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:85142]

Description

class A
end

class B
end

if defined?(A::B)
  puts "defined"

  puts A::B
else
  puts "not defined"
end

When running this script with ruby 2.5.0 i get:

defined
Traceback (most recent call last):
test.rb:10:in `<main>': uninitialized constant A::B (NameError)
Did you mean?  B

while my expectation was that after the top-level constant lookup was removed from ruby 2.5, defined? would return false and i would actually get

not defined

as output


Related issues 1 (0 open1 closed)

Related to Ruby master - Feature #11547: remove top-level constant lookupClosedActions
Actions #2

Updated by nobu (Nobuyoshi Nakada) almost 7 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r62071.


defined? returns nil for toplevel constant lookup

  • variable.c (rb_const_defined_0): toplevel constant lookup has
    been removed, should return nil too.
    [ruby-core:85142] [Bug #14407] [Fix GH-1800]

From: Gonzalo

Actions #3

Updated by nobu (Nobuyoshi Nakada) almost 7 years ago

  • Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN to 2.3: DONTNEED, 2.4: DONTNEED, 2.5: REQUIRED

Updated by naruse (Yui NARUSE) almost 7 years ago

  • Backport changed from 2.3: DONTNEED, 2.4: DONTNEED, 2.5: REQUIRED to 2.3: DONTNEED, 2.4: DONTNEED, 2.5: DONE

ruby_2_5 r62568 merged revision(s) 62071.

Actions #5

Updated by Eregon (Benoit Daloze) almost 3 years ago

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0