Module#ancestors should not return superclasses of refinements
[ruby-core:86949] [Bug #14744] Reported by Eregon (Benoit Daloze). Thanks!
This commit is contained in:
parent
70510d1545
commit
754adbee91
5
class.c
5
class.c
@ -1347,8 +1347,13 @@ VALUE
|
|||||||
rb_mod_ancestors(VALUE mod)
|
rb_mod_ancestors(VALUE mod)
|
||||||
{
|
{
|
||||||
VALUE p, ary = rb_ary_new();
|
VALUE p, ary = rb_ary_new();
|
||||||
|
VALUE refined_class = Qnil;
|
||||||
|
if (FL_TEST(mod, RMODULE_IS_REFINEMENT)) {
|
||||||
|
refined_class = rb_refinement_module_get_refined_class(mod);
|
||||||
|
}
|
||||||
|
|
||||||
for (p = mod; p; p = RCLASS_SUPER(p)) {
|
for (p = mod; p; p = RCLASS_SUPER(p)) {
|
||||||
|
if (p == refined_class) break;
|
||||||
if (p != RCLASS_ORIGIN(p)) continue;
|
if (p != RCLASS_ORIGIN(p)) continue;
|
||||||
if (BUILTIN_TYPE(p) == T_ICLASS) {
|
if (BUILTIN_TYPE(p) == T_ICLASS) {
|
||||||
rb_ary_push(ary, RBASIC(p)->klass);
|
rb_ary_push(ary, RBASIC(p)->klass);
|
||||||
|
@ -2559,6 +2559,18 @@ class TestRefinement < Test::Unit::TestCase
|
|||||||
assert_equal(:refined, Bug17822::Client.call_foo)
|
assert_equal(:refined, Bug17822::Client.call_foo)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_ancestors
|
||||||
|
refinement = nil
|
||||||
|
as = nil
|
||||||
|
Module.new do
|
||||||
|
refine Array do
|
||||||
|
refinement = self
|
||||||
|
as = ancestors
|
||||||
|
end
|
||||||
|
end
|
||||||
|
assert_equal([refinement], as, "[ruby-core:86949] [Bug #14744]")
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def eval_using(mod, s)
|
def eval_using(mod, s)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user