mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
Work around infinite loop when overriding method visibility in prepended module (#3201)
For ZSUPER methods with no defined class for the method entry, start the next lookup at the superclass of the origin class of the method owner, instead of the superclass of the method owner. Fixes [Bug #16942]
This commit is contained in:
parent
9491bd89da
commit
ad0eccf840
Notes:
git
2020-06-10 08:31:29 +09:00
Merged-By: jeremyevans <code@jeremyevans.net>
2 changed files with 23 additions and 2 deletions
4
proc.c
4
proc.c
|
@ -1572,12 +1572,12 @@ mnew_internal(const rb_method_entry_t *me, VALUE klass, VALUE iclass,
|
|||
}
|
||||
if (me->def->type == VM_METHOD_TYPE_ZSUPER) {
|
||||
if (me->defined_class) {
|
||||
VALUE klass = RCLASS_SUPER(RCLASS_ORIGIN(me->defined_class));
|
||||
VALUE klass = RCLASS_SUPER(RCLASS_ORIGIN(me->defined_class));
|
||||
id = me->def->original_id;
|
||||
me = (rb_method_entry_t *)rb_callable_method_entry_with_refinements(klass, id, &iclass);
|
||||
}
|
||||
else {
|
||||
VALUE klass = RCLASS_SUPER(me->owner);
|
||||
VALUE klass = RCLASS_SUPER(RCLASS_ORIGIN(me->owner));
|
||||
id = me->def->original_id;
|
||||
me = rb_method_entry_without_refinements(klass, id, &iclass);
|
||||
}
|
||||
|
|
|
@ -1181,6 +1181,27 @@ class TestMethod < Test::Unit::TestCase
|
|||
assert_separately [], "RubyVM::InstructionSequence.compile_option = {trace_instruction: false}\n" + body
|
||||
end
|
||||
|
||||
def test_zsuper_private_override_instance_method
|
||||
assert_separately(%w(--disable-gems), <<-'end;', timeout: 30)
|
||||
# Bug #16942 [ruby-core:98691]
|
||||
module M
|
||||
def x
|
||||
end
|
||||
end
|
||||
|
||||
module M2
|
||||
prepend Module.new
|
||||
include M
|
||||
private :x
|
||||
end
|
||||
|
||||
::Object.prepend(M2)
|
||||
|
||||
m = Object.instance_method(:x)
|
||||
assert_equal M, m.owner
|
||||
end;
|
||||
end
|
||||
|
||||
def test_eqq
|
||||
assert_operator(0.method(:<), :===, 5)
|
||||
assert_not_operator(0.method(:<), :===, -5)
|
||||
|
|
Loading…
Add table
Reference in a new issue