[前][次][番号順一覧][スレッド一覧]

ruby-changes:39800

From: nobu <ko1@a...>
Date: Wed, 16 Sep 2015 20:39:57 +0900 (JST)
Subject: [ruby-changes:39800] nobu:r51881 (trunk): variable.c: fail if frozen

nobu	2015-09-16 20:39:29 +0900 (Wed, 16 Sep 2015)

  New Revision: 51881

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=51881

  Log:
    variable.c: fail if frozen
    
    * variable.c (set_const_visibility): fail if the class/module is
      frozen.  [ruby-core:70828] [Bug #11532]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_module.rb
    trunk/variable.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 51880)
+++ ChangeLog	(revision 51881)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Sep 16 20:39:26 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* vm_core.h (ENABLE_VM_OBJSPACE): enable per-VM object space on
Index: variable.c
===================================================================
--- variable.c	(revision 51880)
+++ variable.c	(revision 51881)
@@ -2601,6 +2601,7 @@ set_const_visibility(VALUE mod, int argc https://github.com/ruby/ruby/blob/trunk/variable.c#L2601
     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()));
Index: test/ruby/test_module.rb
===================================================================
--- test/ruby/test_module.rb	(revision 51880)
+++ test/ruby/test_module.rb	(revision 51881)
@@ -1948,6 +1948,25 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L1948
     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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]