ruby-changes:26721
From: shugo <ko1@a...>
Date: Fri, 11 Jan 2013 10:10:00 +0900 (JST)
Subject: [ruby-changes:26721] shugo:r38772 (trunk): * insns.def (defineclass): private constants should not be accessed
shugo 2013-01-11 09:58:08 +0900 (Fri, 11 Jan 2013) New Revision: 38772 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=38772 Log: * 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. Modified files: trunk/ChangeLog trunk/insns.def trunk/test/ruby/test_module.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 38771) +++ ChangeLog (revision 38772) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Fri Jan 11 09:56:22 2013 Shugo Maeda <shugo@r...> + + * 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@r...> * lib/rbconfig/obsolete.rb (respond_to_missing?): use send because Index: insns.def =================================================================== --- insns.def (revision 38771) +++ insns.def (revision 38772) @@ -949,7 +949,7 @@ defineclass https://github.com/ruby/ruby/blob/trunk/insns.def#L949 /* 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)); Index: test/ruby/test_module.rb =================================================================== --- test/ruby/test_module.rb (revision 38771) +++ test/ruby/test_module.rb (revision 38772) @@ -1604,6 +1604,26 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1604 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) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/