ruby-changes:62499
From: nagachika <ko1@a...>
Date: Sat, 1 Aug 2020 17:34:11 +0900 (JST)
Subject: [ruby-changes:62499] 23d130a9dd (ruby_2_7): merge revision(s) d05f04d27dd86c67e4a8dfff4392f806cf577bdf: [Backport #16931]
https://git.ruby-lang.org/ruby.git/commit/?id=23d130a9dd From 23d130a9ddcaf766d6ce309f8518b434a2537fc1 Mon Sep 17 00:00:00 2001 From: nagachika <nagachika@r...> Date: Sat, 1 Aug 2020 17:33:56 +0900 Subject: merge revision(s) d05f04d27dd86c67e4a8dfff4392f806cf577bdf: [Backport #16931] Fixed `defined?` against protected method call Protected methods are restricted to be called according to the class/module in where it is defined, not the actual receiver's class. [Bug #16931] diff --git a/test/ruby/test_defined.rb b/test/ruby/test_defined.rb index 387472a..e1571d5 100644 --- a/test/ruby/test_defined.rb +++ b/test/ruby/test_defined.rb @@ -59,6 +59,7 @@ class TestDefined < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_defined.rb#L59 f = Foo.new assert_nil(defined?(f.foo)) # protected method f.bar(f) { |v| assert(v) } + f.bar(Class.new(Foo).new) { |v| assert(v, "inherited protected method") } end def test_defined_undefined_method diff --git a/version.h b/version.h index 8b6e0ee..8c5893a 100644 --- a/version.h +++ b/version.h @@ -2,7 +2,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L2 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR #define RUBY_VERSION_TEENY 1 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR -#define RUBY_PATCHLEVEL 116 +#define RUBY_PATCHLEVEL 117 #define RUBY_RELEASE_YEAR 2020 #define RUBY_RELEASE_MONTH 8 diff --git a/vm_insnhelper.c b/vm_insnhelper.c index 2ac006a..c0d9092 100644 --- a/vm_insnhelper.c +++ b/vm_insnhelper.c @@ -3551,7 +3551,7 @@ vm_defined(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t op_ https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3551 case METHOD_VISI_PRIVATE: break; case METHOD_VISI_PROTECTED: - if (!rb_obj_is_kind_of(GET_SELF(), rb_class_real(klass))) { + if (!rb_obj_is_kind_of(GET_SELF(), rb_class_real(me->defined_class))) { break; } case METHOD_VISI_PUBLIC: -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/