vm_method.c: NameError at refined method alias

* vm_method.c (rb_alias): raise a NameError when creating alias to
  a refined method if the original method of the refined method is
  not defined.  [ruby-core:67523] [Bug #10731]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49221 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-01-12 07:45:49 +00:00
Родитель 2f56ebe8f7
Коммит 1abd51ad91
3 изменённых файлов: 34 добавлений и 1 удалений

Просмотреть файл

@ -1,3 +1,9 @@
Mon Jan 12 16:45:46 2015 Seiei Higa <hanachin@gmail.com>
* vm_method.c (rb_alias): raise a NameError when creating alias to
a refined method if the original method of the refined method is
not defined. [ruby-core:67523] [Bug #10731]
Mon Jan 12 13:53:17 2015 SHIBATA Hiroshi <shibata.hiroshi@gmail.com>
* math.c (math_atan2): improve documentation.

Просмотреть файл

@ -1192,6 +1192,31 @@ class TestRefinement < Test::Unit::TestCase
end;
end
def test_alias_refined_method
assert_separately([], <<-"end;")
bug10731 = '[ruby-core:67523] [Bug #10731]'
class C
end
module RefinementBug
refine C do
def foo
end
def bar
end
end
end
assert_raise(NameError, bug10731) do
class C
alias foo bar
end
end
end;
end
private
def eval_using(mod, s)

Просмотреть файл

@ -1278,7 +1278,9 @@ rb_alias(VALUE klass, ID name, ID def)
again:
orig_me = search_method(klass, def, &defined_class);
if (UNDEFINED_METHOD_ENTRY_P(orig_me)) {
if (UNDEFINED_METHOD_ENTRY_P(orig_me) ||
(orig_me->def->type == VM_METHOD_TYPE_REFINED &&
UNDEFINED_METHOD_ENTRY_P(orig_me->def->body.orig_me))) {
if ((!RB_TYPE_P(klass, T_MODULE)) ||
(orig_me = search_method(rb_cObject, def, 0),
UNDEFINED_METHOD_ENTRY_P(orig_me))) {