From 6ea002a7a28ac11424798f448f1765ccf0513b95 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 19 Jul 2016 06:39:01 +0000 Subject: [PATCH] variable.c: exclude private constants * variable.c (rb_local_constants_i): exclude private constants when excluding inherited constants too. [Bug #12345] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55705 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ test/ruby/test_module.rb | 2 ++ variable.c | 2 +- 3 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 7a82244201..23394ccd1c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Tue Jul 19 15:38:59 2016 Nobuyoshi Nakada + + * variable.c (rb_local_constants_i): exclude private constants + when excluding inherited constants too. [Bug #12345] + Sun Jul 17 23:42:00 2016 Kenta Murata * numeric.c (num_finite_p, num_infinite_p): Add Numeric#finite? and diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 92c3dfd6eb..0f9351c57d 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -1423,6 +1423,8 @@ class TestModule < Test::Unit::TestCase def test_constants_with_private_constant assert_not_include(::TestModule.constants, :PrivateClass) + assert_not_include(::TestModule.constants(true), :PrivateClass) + assert_not_include(::TestModule.constants(false), :PrivateClass) end def test_toplevel_private_constant diff --git a/variable.c b/variable.c index 4d3222b5db..0966685690 100644 --- a/variable.c +++ b/variable.c @@ -2399,7 +2399,7 @@ sv_i(ID key, VALUE v, void *a) static enum rb_id_table_iterator_result rb_local_constants_i(ID const_name, VALUE const_value, void *ary) { - if (rb_is_const_id(const_name)) { + if (rb_is_const_id(const_name) && !RB_CONST_PRIVATE_P((rb_const_entry_t *)const_value)) { rb_ary_push((VALUE)ary, ID2SYM(const_name)); } return ID_TABLE_CONTINUE;