diff options
author | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-01-11 00:58:08 +0000 |
---|---|---|
committer | shugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-01-11 00:58:08 +0000 |
commit | bb54d0ae4cafaecfecb2299d7acacaa642afce5c (patch) | |
tree | 5c599e9e0d9aabf9b8f2bc2f6c7962a35e53139c | |
parent | c0c381e4d55dc42319e24b5a569b6fe8d6fdf84f (diff) |
* insns.def (defineclass): private constants should not be accessed
by scoped module definitions. The bug was introduced in r38495.
* test/ruby/test_module.rb: related test.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38772 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | insns.def | 2 | ||||
-rw-r--r-- | test/ruby/test_module.rb | 20 |
3 files changed, 28 insertions, 1 deletions
@@ -1,3 +1,10 @@ +Fri Jan 11 09:56:22 2013 Shugo Maeda <shugo@ruby-lang.org> + + * insns.def (defineclass): private constants should not be accessed + by scoped module definitions. The bug was introduced in r38495. + + * test/ruby/test_module.rb: related test. + Fri Jan 11 02:11:59 2013 Shugo Maeda <shugo@ruby-lang.org> * lib/rbconfig/obsolete.rb (respond_to_missing?): use send because @@ -949,7 +949,7 @@ defineclass /* find klass */ if ((klass = vm_search_const_defined_class(cbase, id)) != 0) { klass = VM_DEFINECLASS_SCOPED_P(flags) ? - rb_const_get_at(klass, id) : rb_public_const_get_at(klass, id); + rb_public_const_get_at(klass, id) : rb_const_get_at(klass, id); /* already exist */ if (!RB_TYPE_P(klass, T_MODULE)) { rb_raise(rb_eTypeError, "%s is not a module", rb_id2name(id)); diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 340c37762a..6e25dac1d5 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1604,6 +1604,26 @@ class TestModule < Test::Unit::TestCase assert_top_method_is_private(:define_method) end + module PrivateConstantReopen + PRIVATE_CONSTANT = true + private_constant :PRIVATE_CONSTANT + end + + def test_private_constant_reopen + assert_raise(NameError) do + eval <<-EOS, TOPLEVEL_BINDING + module TestModule::PrivateConstantReopen::PRIVATE_CONSTANT + end + EOS + end + assert_raise(NameError) do + eval <<-EOS, TOPLEVEL_BINDING + class TestModule::PrivateConstantReopen::PRIVATE_CONSTANT + end + EOS + end + end + private def assert_top_method_is_private(method) |