ruby-changes:51614
From: nagachika <ko1@a...>
Date: Mon, 2 Jul 2018 17:53:59 +0900 (JST)
Subject: [ruby-changes:51614] nagachika:r63825 (ruby_2_5): merge revision(s) 63696: [Backport #14853]
nagachika 2018-07-02 17:53:52 +0900 (Mon, 02 Jul 2018) New Revision: 63825 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63825 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_5/ Modified files: branches/ruby_2_5/test/ruby/test_module.rb branches/ruby_2_5/variable.c branches/ruby_2_5/version.h Index: ruby_2_5/variable.c =================================================================== --- ruby_2_5/variable.c (revision 63824) +++ ruby_2_5/variable.c (revision 63825) @@ -2257,6 +2257,7 @@ rb_const_search(VALUE klass, ID id, int https://github.com/ruby/ruby/blob/trunk/ruby_2_5/variable.c#L2257 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_5/version.h =================================================================== --- ruby_2_5/version.h (revision 63824) +++ ruby_2_5/version.h (revision 63825) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/version.h#L1 #define RUBY_VERSION "2.5.2" #define RUBY_RELEASE_DATE "2018-07-02" -#define RUBY_PATCHLEVEL 63 +#define RUBY_PATCHLEVEL 64 #define RUBY_RELEASE_YEAR 2018 #define RUBY_RELEASE_MONTH 7 Index: ruby_2_5/test/ruby/test_module.rb =================================================================== --- ruby_2_5/test/ruby/test_module.rb (revision 63824) +++ ruby_2_5/test/ruby/test_module.rb (revision 63825) @@ -1352,21 +1352,55 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_5/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_5 =================================================================== --- ruby_2_5 (revision 63824) +++ ruby_2_5 (revision 63825) Property changes on: ruby_2_5 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r63696 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/