Bug #3422

Object.const_get(:A, false) can access BasicObject::A

Added by Magnus Holm almost 4 years ago. Updated over 1 year ago.

[ruby-core:30719]
Status:Closed
Priority:Normal
Assignee:Motohiro KOSAKI
Category:core
Target version:2.0.0
ruby -v:- Backport:

Description

=begin
From the documentation of Module#const_get(sym, inherit=true):

If the constant is not defined or is defined by the ancestors and inherit is false, NameError will be raised.

Yet, this works fine:

BasicObject::A = 1
Object.const_get(:A, false) # => 1

While I haven't tested it, I believe the attached patch should fix the issue.
=end

patch.diff Magnifier - Patch (417 Bytes) Magnus Holm, 06/11/2010 04:11 AM


Related issues

Duplicates ruby-trunk - Bug #3423: Inconsistent behaviour of Module#const_get with included ... Closed 06/11/2010
Duplicated by ruby-trunk - Bug #5143: include not properly registering modular methods Closed 08/02/2011
Duplicated by ruby-trunk - Bug #5154: method_missing and module scope, regression in 1.9.3 Closed 08/03/2011

Associated revisions

Revision 32283
Added by Yukihiro Matsumoto almost 3 years ago

  • variable.c (rbconstget0): should not look for superclasses if the second optional argument is given for #constget(). fix [Bug #3422] [Bug #3423]

Revision 32327
Added by Nobuyoshi Nakada almost 3 years ago

  • test/ruby/test_module.rb: tests for [Bug #3422] and [Bug #3423].

History

#1 Updated by Yui NARUSE almost 3 years ago

  • Status changed from Open to Assigned
  • Assignee set to Yukihiro Matsumoto
  • Target version set to 1.9.3

#2 Updated by Yukihiro Matsumoto almost 3 years ago

the patch should be applied before 1.9.3.

matz.

#3 Updated by Yukihiro Matsumoto almost 3 years ago

Sorry, this issue must be covered by #3423.

matz.

#4 Updated by Yukihiro Matsumoto almost 3 years ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r32283.
Magnus, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • variable.c (rbconstget0): should not look for superclasses if the second optional argument is given for #constget(). fix [Bug #3422] [Bug #3423]

#5 Updated by Yui NARUSE almost 3 years ago

  • Status changed from Closed to Assigned
  • Priority changed from Low to Normal

r32283 breaks following codes:

module LangModuleSpecInObject
module LangModuleTop
end
end
include LangModuleSpecInObject
module LangModuleTop
end #=> NameError: uninitialized constant LangModuleTop

class BasicObject
end #=> NameError: uninitialized constant BasicObject

#6 Updated by Yui NARUSE almost 3 years ago

  • Status changed from Assigned to Closed

Yui NARUSE wrote:

r32283 breaks following codes:

Oops, r32342 fix this. thanks!

#7 Updated by Yui NARUSE almost 3 years ago

  • Status changed from Closed to Assigned

Following code still doesn't work:

module LangModuleSpecInObject
module LangModuleTop
end
end
include LangModuleSpecInObject
p LangModuleTop
end
p LangModuleSpecInObject::LangModuleTop == LangModuleTop #=> false (it should be true)

#8 Updated by Yukihiro Matsumoto almost 3 years ago

Can you elaborate?

If I remove "end" in the line 7, it works for me (otherwise, it was an syntax error).

matz.

#9 Updated by Yui NARUSE almost 3 years ago

Oh sorry, it must be:

module LangModuleSpecInObject
module LangModuleTop
end
end
include LangModuleSpecInObject
module LangModuleTop
end
p LangModuleSpecInObject::LangModuleTop == LangModuleTop

#10 Updated by Motohiro KOSAKI almost 3 years ago

Oh sorry, it must be:

module LangModuleSpecInObject
module LangModuleTop
end
end
include LangModuleSpecInObject
module LangModuleTop
end
p LangModuleSpecInObject::LangModuleTop == LangModuleTop

matz, could you please answer to Yui?

#11 Updated by Motohiro KOSAKI over 2 years ago

Matz, I think we need to decide either 1) revert r32283 or 2) fix naruse reported regression. Everybody know you are busy. But I believe 1.9.3 have no regression.....

#12 Updated by Nobuyoshi Nakada over 2 years ago

  • Status changed from Assigned to Closed

#13 Updated by Magnus Holm over 2 years ago

On Sat, Sep 3, 2011 at 04:57, Nobuyoshi Nakada nobu@ruby-lang.org wrote:

Issue #3422 has been updated by Nobuyoshi Nakada.

Status changed from Assigned to Closed

Why is this issue closed? Is the current behaviour acceptable?

#14 Updated by Motohiro KOSAKI over 2 years ago

  • ruby -v changed from ruby 1.9.2dev (2010-05-31 revision 28117) [x86_64-darwin10.3.0] to -

Why is this issue closed? Is the current behaviour acceptable?

Can you still reproduce this issue?

#15 Updated by Magnus Holm over 2 years ago

Why is this issue closed? Is the current behaviour acceptable?

Can you still reproduce this issue?

Not the original issue. But it seemed to me that this issue was left
open because it introduced other problems (discussed above). Now that
this one has closed, I'm wondering what happened to this new issue?

#16 Updated by Yui NARUSE over 2 years ago

  • ruby -v changed from - to ruby 1.9.2dev (2010-05-31 revision 28117) [x86_64-darwin10.3.0]

nobu lazily closed this ticket without the revision reference: r33163.

#17 Updated by Motohiro KOSAKI over 2 years ago

  • ruby -v changed from ruby 1.9.2dev (2010-05-31 revision 28117) [x86_64-darwin10.3.0] to -

Why is this issue closed? Is the current behaviour acceptable?

Can you still reproduce this issue?

Not the original issue. But it seemed to me that this issue was left
open because it introduced other problems (discussed above). Now that
this one has closed, I'm wondering what happened to this new issue?

As Yui explained, nobu fixed and commited it into ruby193 branch. so
I'm not thinking the regression above discussed disappeared. If you run
latest ruby
193 branch and find any issue, please let us know asap.

Thank you for paying attention our bugfixes effort.

#18 Updated by Alexander E. Fischer over 1 year ago

Could the following problem be related to this change? "Including namespace module through RSpec config in Ruby 1.9.3":http://stackoverflow.com/questions/13042298/including-namespace-module-through-rspec-config-in-ruby-1-9-3

If so, wouldn't it be a better idea to revert this?

#19 Updated by Motohiro KOSAKI over 1 year ago

  • Status changed from Closed to Open

#20 Updated by Yusuke Endoh over 1 year ago

  • Status changed from Open to Assigned
  • Target version changed from 1.9.3 to 2.0.0

Matz, do you think that it should be changed again?
IMO, in principle, I don't think that it is a good idea to change the behavior so many times.

Yusuke Endoh mame@tsg.ne.jp

#21 Updated by Shugo Maeda over 1 year ago

  • Assignee changed from Yukihiro Matsumoto to Motohiro KOSAKI

mame (Yusuke Endoh) wrote:

Matz, do you think that it should be changed again?
IMO, in principle, I don't think that it is a good idea to change the behavior so many times.

I'm not sure why this ticket has been reopened, but if it's because of the following comment, this ticket can be closed, because the request has already been rejected in #7213.

Could the following problem be related to this change? "Including namespace module through RSpec config in Ruby 1.9.3":http://stackoverflow.com/questions/13042298/including-namespace-module-through-rspec-config-in-ruby-1-9-3

If so, wouldn't it be a better idea to revert this?

Kosaki-san, why did you reopen this ticket?

#22 Updated by Motohiro KOSAKI over 1 year ago

  • Status changed from Assigned to Closed

Kosaki-san, why did you reopen this ticket?

Sorry, my memory was lost and I don't remember why. but I suspect your guess is right and we can close this ticket.

Also available in: Atom PDF