ruby-changes:45289
From: nobu <ko1@a...>
Date: Wed, 18 Jan 2017 14:23:58 +0900 (JST)
Subject: [ruby-changes:45289] nobu:r57362 (trunk): vm_method.c: resolve refined method to undef
nobu 2017-01-18 14:23:53 +0900 (Wed, 18 Jan 2017) New Revision: 57362 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57362 Log: vm_method.c: resolve refined method to undef * vm_method.c (rb_undef): resolve the method entry which refines a prepended method entry. [ruby-core:78944] [Bug #13096] Modified files: trunk/test/ruby/test_refinement.rb trunk/vm_method.c Index: vm_method.c =================================================================== --- vm_method.c (revision 57361) +++ vm_method.c (revision 57362) @@ -1171,7 +1171,7 @@ rb_attr(VALUE klass, ID id, int read, in https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1171 void rb_undef(VALUE klass, ID id) { - rb_method_entry_t *me; + const rb_method_entry_t *me; if (NIL_P(klass)) { rb_raise(rb_eTypeError, "no class to undef method"); @@ -1182,6 +1182,9 @@ rb_undef(VALUE klass, ID id) https://github.com/ruby/ruby/blob/trunk/vm_method.c#L1182 } me = search_method(klass, id, 0); + if (me && me->def->type == VM_METHOD_TYPE_REFINED) { + me = rb_resolve_refined_method(Qnil, me); + } if (UNDEFINED_METHOD_ENTRY_P(me) || UNDEFINED_REFINED_METHOD_P(me->def)) { Index: test/ruby/test_refinement.rb =================================================================== --- test/ruby/test_refinement.rb (revision 57361) +++ test/ruby/test_refinement.rb (revision 57362) @@ -1474,6 +1474,25 @@ class TestRefinement < Test::Unit::TestC https://github.com/ruby/ruby/blob/trunk/test/ruby/test_refinement.rb#L1474 INPUT end + def test_undef_prepended_method + bug13096 = '[ruby-core:78944] [Bug #13096]' + klass = EnvUtil.labeled_class("X") do + def foo; end + end + klass.prepend(Module.new) + ext = EnvUtil.labeled_module("Ext") do + refine klass do + def foo + end + end + end + assert_nothing_raised(NameError, bug13096) do + klass.class_eval do + undef :foo + end + end + end + def test_call_refined_method_in_duplicate_module bug10885 = '[ruby-dev:48878]' assert_in_out_err([], <<-INPUT, [], [], bug10885) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/