From 59f5fa102af7777ba1c620b764fa05f62dad9b54 Mon Sep 17 00:00:00 2001 From: shugo Date: Mon, 30 Sep 2013 01:49:21 +0000 Subject: * vm_method.c (rb_undef): raise a NameError if the original method of a refined method is not defined. * vm_insnhelper.c (rb_method_entry_eq): added NULL check to avoid SEGV. * test/ruby/test_refinement.rb: related test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43090 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_refinement.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_refinement.rb b/test/ruby/test_refinement.rb index 60681b2f1a..92f293cad5 100644 --- a/test/ruby/test_refinement.rb +++ b/test/ruby/test_refinement.rb @@ -1016,6 +1016,50 @@ class TestRefinement < Test::Unit::TestCase assert_not_send([FooSub, :method_defined?, :z]) end + def test_undef_refined_method + bug8966 = '[ruby-core:57466] [Bug #8966]' + + assert_in_out_err([], <<-INPUT, ["NameError"], [], bug8966) + module Foo + refine Object do + def foo + puts "foo" + end + end + end + + using Foo + + class Object + begin + undef foo + rescue Exception => e + p e.class + end + end + INPUT + + assert_in_out_err([], <<-INPUT, ["NameError"], [], bug8966) + module Foo + refine Object do + def foo + puts "foo" + end + end + end + + # without `using Foo' + + class Object + begin + undef foo + rescue Exception => e + p e.class + end + end + INPUT + end + private def eval_using(mod, s) -- cgit v1.2.3