ruby-changes:59135
From: nagachika <ko1@a...>
Date: Mon, 9 Dec 2019 22:01:24 +0900 (JST)
Subject: [ruby-changes:59135] 15eba4ed0e (ruby_2_6): merge revision(s) e1b592b508c72a56ae012869d97fe1580ff87246,d10451f3fd51f577e704db770de48d05044eb45c: [Backport #15758]
https://git.ruby-lang.org/ruby.git/commit/?id=15eba4ed0e From 15eba4ed0ebb4e019a037b0af10b34fdbc85e03a Mon Sep 17 00:00:00 2001 From: nagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> Date: Mon, 9 Dec 2019 12:06:38 +0000 Subject: merge revision(s) e1b592b508c72a56ae012869d97fe1580ff87246,d10451f3fd51f577e704db770de48d05044eb45c: [Backport #15758] test_module.rb: fix a typo * test/ruby/test_module.rb (TestModule#test_nested_get): fix a typo. nested module's name is a qualified path. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67471 b2dd03c8-39d4-4d8f-98ff-823fe69b080e object.c: fix searching nested const paths * object.c (rb_mod_const_get, rb_mod_const_defined): nested const paths should not search from toplevel constants. [ruby-core:92202] [Bug #15758] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67472 b2dd03c8-39d4-4d8f-98ff-823fe69b080e git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_6@67830 b2dd03c8-39d4-4d8f-98ff-823fe69b080e diff --git a/object.c b/object.c index 4f844be..7928592 100644 --- a/object.c +++ b/object.c @@ -2530,7 +2530,19 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod) https://github.com/ruby/ruby/blob/trunk/object.c#L2530 name = ID2SYM(id); goto wrong_name; } - mod = RTEST(recur) ? rb_const_get(mod, id) : rb_const_get_at(mod, id); +#if 0 + mod = rb_const_get_0(mod, id, beglen > 0 || !RTEST(recur), RTEST(recur), FALSE); +#else + if (!RTEST(recur)) { + mod = rb_const_get_at(mod, id); + } + else if (beglen == 0) { + mod = rb_const_get(mod, id); + } + else { + mod = rb_const_get_from(mod, id); + } +#endif } return mod; @@ -2678,16 +2690,27 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod) https://github.com/ruby/ruby/blob/trunk/object.c#L2690 name = ID2SYM(id); goto wrong_name; } - if (RTEST(recur)) { - if (!rb_const_defined(mod, id)) - return Qfalse; - mod = rb_const_get(mod, id); - } - else { + +#if 0 + mod = rb_const_search(mod, id, beglen > 0 || !RTEST(recur), RTEST(recur), FALSE); + if (mod == Qundef) return Qfalse; +#else + if (!RTEST(recur)) { if (!rb_const_defined_at(mod, id)) return Qfalse; mod = rb_const_get_at(mod, id); } + else if (beglen == 0) { + if (!rb_const_defined(mod, id)) + return Qfalse; + mod = rb_const_get(mod, id); + } + else { + if (!rb_const_defined_from(mod, id)) + return Qfalse; + mod = rb_const_get_from(mod, id); + } +#endif if (p < pend && !RB_TYPE_P(mod, T_MODULE) && !RB_TYPE_P(mod, T_CLASS)) { rb_raise(rb_eTypeError, "%"PRIsVALUE" does not refer to class/module", diff --git a/test/ruby/test_module.rb b/test/ruby/test_module.rb index 9e9eb13..ef78475 100644 --- a/test/ruby/test_module.rb +++ b/test/ruby/test_module.rb @@ -294,8 +294,11 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L294 end def test_nested_get - assert_equal Other, Object.const_get([self.class, Other].join('::')) + assert_equal Other, Object.const_get([self.class, 'Other'].join('::')) assert_equal User::USER, self.class.const_get([User, 'USER'].join('::')) + assert_raise(NameError) { + Object.const_get([self.class.name, 'String'].join('::')) + } end def test_nested_get_symbol @@ -328,6 +331,7 @@ class TestModule < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_module.rb#L331 assert_send([Object, :const_defined?, [self.class.name, 'Other'].join('::')]) assert_send([self.class, :const_defined?, 'User::USER']) assert_not_send([self.class, :const_defined?, 'User::Foo']) + assert_not_send([Object, :const_defined?, [self.class.name, 'String'].join('::')]) end def test_nested_defined_symbol diff --git a/version.h b/version.h index b38ae7b..65491c2 100644 --- a/version.h +++ b/version.h @@ -1,9 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L1 #define RUBY_VERSION "2.6.6" #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 117 +#define RUBY_PATCHLEVEL 118 #define RUBY_RELEASE_YEAR 2019 -#define RUBY_RELEASE_MONTH 11 +#define RUBY_RELEASE_MONTH 12 #define RUBY_RELEASE_DAY 9 #include "ruby/version.h" -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/