summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-18 05:23:53 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-01-18 05:23:53 +0000
commitb38823cecab368081d3851c721e4ee89121cbcd9 (patch)
tree5f2251d2fbec79cd6e08455d6626ca6cf3a45ca8
parent54a77d2044148bb442340f93747e1f345b6ca401 (diff)
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@57362 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--test/ruby/test_refinement.rb19
-rw-r--r--vm_method.c5
2 files changed, 23 insertions, 1 deletions
diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb
index 8af9945080..66202cda11 100644
--- a/test/ruby/test_refinement.rb
+++ b/test/ruby/test_refinement.rb
@@ -1474,6 +1474,25 @@ class TestRefinement < Test::Unit::TestCase
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)
diff --git a/vm_method.c b/vm_method.c
index 8aea9b54cc..f4ff7989f2 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -1171,7 +1171,7 @@ rb_attr(VALUE klass, ID id, int read, int write, int ex)
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)
}
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)) {