From d267b2e347b0ef226c132a881ed11a89e622df24 Mon Sep 17 00:00:00 2001 From: mame Date: Sat, 3 Dec 2011 11:52:08 +0000 Subject: * variable.c (set_const_visibility): Module#private_constant has changed the visibility of only the first argument. Now it changes all of them. [ruby-list:48558] * test/ruby/test_module.rb: add a test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33935 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 ++++++++ test/ruby/test_module.rb | 13 +++++++++++++ variable.c | 2 +- 3 files changed, 22 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index e3a335ba4d..05edd3e814 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Sat Dec 3 20:43:14 2011 Yusuke Endoh + + * variable.c (set_const_visibility): Module#private_constant has + changed the visibility of only the first argument. Now it changes + all of them. [ruby-list:48558] + + * test/ruby/test_module.rb: add a test for above. + Sat Dec 3 07:17:29 2011 Nobuyoshi Nakada * Makefile.in (CFLAGS): append ARCH_FLAG. diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 892ab9f593..16485c30d1 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1070,6 +1070,19 @@ class TestModule < Test::Unit::TestCase assert_raise(NameError) { c::FOO } end + def test_private_constant2 + c = Class.new + c.const_set(:FOO, "foo") + c.const_set(:BAR, "bar") + assert_equal("foo", c::FOO) + assert_equal("bar", c::BAR) + c.private_constant(:FOO, :BAR) + assert_raise(NameError) { c::FOO } + assert_raise(NameError) { c::BAR } + assert_equal("foo", c.class_eval("FOO")) + assert_equal("bar", c.class_eval("BAR")) + end + class PrivateClass end private_constant :PrivateClass diff --git a/variable.c b/variable.c index abdb39ad10..fc912d64f8 100644 --- a/variable.c +++ b/variable.c @@ -2119,7 +2119,7 @@ set_const_visibility(VALUE mod, int argc, VALUE *argv, rb_const_flag_t flag) } if (RCLASS_CONST_TBL(mod) && st_lookup(RCLASS_CONST_TBL(mod), (st_data_t)id, &v)) { ((rb_const_entry_t*)v)->flag = flag; - return; + continue; } rb_name_error(id, "constant %s::%s not defined", rb_class2name(mod), rb_id2name(id)); } -- cgit v1.2.3