ruby-changes:50395
From: naruse <ko1@a...>
Date: Wed, 21 Feb 2018 15:16:39 +0900 (JST)
Subject: [ruby-changes:50395] naruse:r62511 (ruby_2_5): merge revision(s) 61484: [Backport #14232]
naruse 2018-02-21 15:16:32 +0900 (Wed, 21 Feb 2018) New Revision: 62511 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62511 Log: merge revision(s) 61484: [Backport #14232] vm_method.c: fix super in refined module * vm_method.c (rb_method_entry_complement_defined_class): clone the original method entry of refined module instance method with the active ICLASS, to track super method chain. [ruby-dev:50390] [Bug #14232] Modified directories: branches/ruby_2_5/ Modified files: branches/ruby_2_5/test/ruby/test_refinement.rb branches/ruby_2_5/version.h branches/ruby_2_5/vm_method.c Index: ruby_2_5/vm_method.c =================================================================== --- ruby_2_5/vm_method.c (revision 62510) +++ ruby_2_5/vm_method.c (revision 62511) @@ -404,10 +404,33 @@ rb_method_entry_clone(const rb_method_en https://github.com/ruby/ruby/blob/trunk/ruby_2_5/vm_method.c#L404 const rb_callable_method_entry_t * rb_method_entry_complement_defined_class(const rb_method_entry_t *src_me, ID called_id, VALUE defined_class) { - rb_method_entry_t *me = rb_method_entry_alloc(called_id, src_me->owner, defined_class, - method_definition_addref_complement(src_me->def)); + rb_method_definition_t *def = src_me->def; + rb_method_entry_t *me; + struct { + const struct rb_method_entry_struct *orig_me; + VALUE owner; + } refined = {0}; + + if (!src_me->defined_class && + def->type == VM_METHOD_TYPE_REFINED && + def->body.refined.orig_me) { + const rb_method_entry_t *orig_me = + rb_method_entry_clone(def->body.refined.orig_me); + RB_OBJ_WRITE((VALUE)orig_me, &orig_me->defined_class, defined_class); + refined.orig_me = orig_me; + refined.owner = orig_me->owner; + def = NULL; + } + else { + def = method_definition_addref_complement(def); + } + me = rb_method_entry_alloc(called_id, src_me->owner, defined_class, def); METHOD_ENTRY_FLAGS_COPY(me, src_me); METHOD_ENTRY_COMPLEMENTED_SET(me); + if (!def) { + def = method_definition_create(VM_METHOD_TYPE_REFINED, called_id); + method_definition_set(me, def, &refined); + } VM_ASSERT(RB_TYPE_P(me->owner, T_MODULE)); Index: ruby_2_5/version.h =================================================================== --- ruby_2_5/version.h (revision 62510) +++ ruby_2_5/version.h (revision 62511) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/version.h#L1 #define RUBY_VERSION "2.5.0" #define RUBY_RELEASE_DATE "2018-02-21" -#define RUBY_PATCHLEVEL 28 +#define RUBY_PATCHLEVEL 29 #define RUBY_RELEASE_YEAR 2018 #define RUBY_RELEASE_MONTH 2 Index: ruby_2_5/test/ruby/test_refinement.rb =================================================================== --- ruby_2_5/test/ruby/test_refinement.rb (revision 62510) +++ ruby_2_5/test/ruby/test_refinement.rb (revision 62511) @@ -2055,6 +2055,25 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/ruby_2_5/test/ruby/test_refinement.rb#L2055 INPUT end + def test_super_from_refined_module + a = EnvUtil.labeled_module("A") do + def foo;"[A#{super}]";end + end + b = EnvUtil.labeled_class("B") do + def foo;"[B]";end + end + c = EnvUtil.labeled_class("C", b) do + include a + def foo;"[C#{super}]";end + end + d = EnvUtil.labeled_module("D") do + refine(a) do + def foo;end + end + end + assert_equal("[C[A[B]]]", c.new.foo, '[ruby-dev:50390] [Bug #14232]') + end + private def eval_using(mod, s) Index: ruby_2_5 =================================================================== --- ruby_2_5 (revision 62510) +++ ruby_2_5 (revision 62511) Property changes on: ruby_2_5 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r61484 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/