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

ruby-changes:52351

From: usa <ko1@a...>
Date: Mon, 27 Aug 2018 22:48:58 +0900 (JST)
Subject: [ruby-changes:52351] usa:r64559 (ruby_2_4): merge revision(s) 63696: [Backport #14853]

usa	2018-08-27 22:48:53 +0900 (Mon, 27 Aug 2018)

  New Revision: 64559

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

  Log:
    merge revision(s) 63696: [Backport #14853]
    
    variable.c: fix receiver on private constant
    
    * variable.c (rb_const_search): fix NameError :receiver attribute
      on private constant, should raise with the included module, not
      the ICLASS.

  Modified directories:
    branches/ruby_2_4/
  Modified files:
    branches/ruby_2_4/test/ruby/test_module.rb
    branches/ruby_2_4/variable.c
    branches/ruby_2_4/version.h
Index: ruby_2_4/version.h
===================================================================
--- ruby_2_4/version.h	(revision 64558)
+++ ruby_2_4/version.h	(revision 64559)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_4/version.h#L1
 #define RUBY_VERSION "2.4.5"
 #define RUBY_RELEASE_DATE "2018-08-27"
-#define RUBY_PATCHLEVEL 316
+#define RUBY_PATCHLEVEL 317
 
 #define RUBY_RELEASE_YEAR 2018
 #define RUBY_RELEASE_MONTH 8
Index: ruby_2_4/variable.c
===================================================================
--- ruby_2_4/variable.c	(revision 64558)
+++ ruby_2_4/variable.c	(revision 64559)
@@ -2304,6 +2304,7 @@ rb_const_search(VALUE klass, ID id, int https://github.com/ruby/ruby/blob/trunk/ruby_2_4/variable.c#L2304
 
 	while ((ce = rb_const_lookup(tmp, id))) {
 	    if (visibility && RB_CONST_PRIVATE_P(ce)) {
+		if (BUILTIN_TYPE(tmp) == T_ICLASS) tmp = RBASIC(tmp)->klass;
 		rb_name_err_raise("private constant %2$s::%1$s referenced",
 				  tmp, ID2SYM(id));
 	    }
Index: ruby_2_4/test/ruby/test_module.rb
===================================================================
--- ruby_2_4/test/ruby/test_module.rb	(revision 64558)
+++ ruby_2_4/test/ruby/test_module.rb	(revision 64559)
@@ -1352,21 +1352,55 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_4/test/ruby/test_module.rb#L1352
     assert_raise(ArgumentError, bug8540) { c.new.send :foo= }
   end
 
-  def test_private_constant
+  def test_private_constant_in_class
     c = Class.new
     c.const_set(:FOO, "foo")
     assert_equal("foo", c::FOO)
     c.private_constant(:FOO)
-    assert_raise(NameError) { c::FOO }
+    e = assert_raise(NameError) {c::FOO}
+    assert_equal(c, e.receiver)
+    assert_equal(:FOO, e.name)
     assert_equal("foo", c.class_eval("FOO"))
     assert_equal("foo", c.const_get("FOO"))
     $VERBOSE, verbose = nil, $VERBOSE
     c.const_set(:FOO, "foo")
     $VERBOSE = verbose
-    assert_raise(NameError) { c::FOO }
-    assert_raise_with_message(NameError, /#{c}::FOO/) do
+    e = assert_raise(NameError) {c::FOO}
+    assert_equal(c, e.receiver)
+    assert_equal(:FOO, e.name)
+    e = assert_raise_with_message(NameError, /#{c}::FOO/) do
       Class.new(c)::FOO
     end
+    assert_equal(c, e.receiver)
+    assert_equal(:FOO, e.name)
+  end
+
+  def test_private_constant_in_module
+    m = Module.new
+    m.const_set(:FOO, "foo")
+    assert_equal("foo", m::FOO)
+    m.private_constant(:FOO)
+    e = assert_raise(NameError) {m::FOO}
+    assert_equal(m, e.receiver)
+    assert_equal(:FOO, e.name)
+    assert_equal("foo", m.class_eval("FOO"))
+    assert_equal("foo", m.const_get("FOO"))
+    $VERBOSE, verbose = nil, $VERBOSE
+    m.const_set(:FOO, "foo")
+    $VERBOSE = verbose
+    e = assert_raise(NameError) {m::FOO}
+    assert_equal(m, e.receiver)
+    assert_equal(:FOO, e.name)
+    e = assert_raise(NameError, /#{m}::FOO/) do
+      Module.new {include m}::FOO
+    end
+    assert_equal(m, e.receiver)
+    assert_equal(:FOO, e.name)
+    e = assert_raise(NameError, /#{m}::FOO/) do
+      Class.new {include m}::FOO
+    end
+    assert_equal(m, e.receiver)
+    assert_equal(:FOO, e.name)
   end
 
   def test_private_constant2
Index: ruby_2_4
===================================================================
--- ruby_2_4	(revision 64558)
+++ ruby_2_4	(revision 64559)

Property changes on: ruby_2_4
___________________________________________________________________
Modified: svn:mergeinfo
## -0,0 +0,1 ##
   Merged /trunk:r63696

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

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