Skip to content

Commit bb54d0a

Browse files
committed
* 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
1 parent c0c381e commit bb54d0a

File tree

3 files changed

+28
-1
lines changed

3 files changed

+28
-1
lines changed

ChangeLog

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
Fri Jan 11 09:56:22 2013 Shugo Maeda <[email protected]>
2+
3+
* insns.def (defineclass): private constants should not be accessed
4+
by scoped module definitions. The bug was introduced in r38495.
5+
6+
* test/ruby/test_module.rb: related test.
7+
18
Fri Jan 11 02:11:59 2013 Shugo Maeda <[email protected]>
29

310
* lib/rbconfig/obsolete.rb (respond_to_missing?): use send because

insns.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -949,7 +949,7 @@ defineclass
949949
/* find klass */
950950
if ((klass = vm_search_const_defined_class(cbase, id)) != 0) {
951951
klass = VM_DEFINECLASS_SCOPED_P(flags) ?
952-
rb_const_get_at(klass, id) : rb_public_const_get_at(klass, id);
952+
rb_public_const_get_at(klass, id) : rb_const_get_at(klass, id);
953953
/* already exist */
954954
if (!RB_TYPE_P(klass, T_MODULE)) {
955955
rb_raise(rb_eTypeError, "%s is not a module", rb_id2name(id));

test/ruby/test_module.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1604,6 +1604,26 @@ def test_private_top_methods
16041604
assert_top_method_is_private(:define_method)
16051605
end
16061606

1607+
module PrivateConstantReopen
1608+
PRIVATE_CONSTANT = true
1609+
private_constant :PRIVATE_CONSTANT
1610+
end
1611+
1612+
def test_private_constant_reopen
1613+
assert_raise(NameError) do
1614+
eval <<-EOS, TOPLEVEL_BINDING
1615+
module TestModule::PrivateConstantReopen::PRIVATE_CONSTANT
1616+
end
1617+
EOS
1618+
end
1619+
assert_raise(NameError) do
1620+
eval <<-EOS, TOPLEVEL_BINDING
1621+
class TestModule::PrivateConstantReopen::PRIVATE_CONSTANT
1622+
end
1623+
EOS
1624+
end
1625+
end
1626+
16071627
private
16081628

16091629
def assert_top_method_is_private(method)

0 commit comments

Comments
 (0)