aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--test/ruby/test_module.rb19
-rw-r--r--variable.c1
3 files changed, 25 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index cf40e8fb25..dffaef56b4 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Wed Sep 16 20:39:26 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * variable.c (set_const_visibility): fail if the class/module is
+ frozen. [ruby-core:70828] [Bug #11532]
+
Wed Sep 16 17:16:43 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
* vm_core.h (ENABLE_VM_OBJSPACE): enable per-VM object space on
diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb
index 18db88f04a..e04152f845 100644
--- a/test/ruby/test_module.rb
+++ b/test/ruby/test_module.rb
@@ -1948,6 +1948,25 @@ class TestModule < Test::Unit::TestCase
end
end
+ def test_frozen_visibility
+ bug11532 = '[ruby-core:70828] [Bug #11532]'
+
+ c = Class.new {const_set(:A, 1)}.freeze
+ assert_raise_with_message(RuntimeError, /frozen class/, bug11532) {
+ c.class_eval {private_constant :A}
+ }
+
+ c = Class.new {const_set(:A, 1); private_constant :A}.freeze
+ assert_raise_with_message(RuntimeError, /frozen class/, bug11532) {
+ c.class_eval {public_constant :A}
+ }
+
+ c = Class.new {const_set(:A, 1)}.freeze
+ assert_raise_with_message(RuntimeError, /frozen class/, bug11532) {
+ c.class_eval {deprecate_constant :A}
+ }
+ end
+
def test_singleton_class_ancestors
feature8035 = '[ruby-core:53171]'
obj = Object.new
diff --git a/variable.c b/variable.c
index 480e00777c..84eaf172c6 100644
--- a/variable.c
+++ b/variable.c
@@ -2601,6 +2601,7 @@ set_const_visibility(VALUE mod, int argc, const VALUE *argv,
rb_const_entry_t *ce;
ID id;
+ rb_frozen_class_p(mod);
if (argc == 0) {
rb_warning("%"PRIsVALUE" with no argument is just ignored",
QUOTE_ID(rb_frame_callee()));