Actions
Bug #17038
closedOn master, ancestry edits can lead to duplicates in Module#ancestors
Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 2.8.0dev (2020-07-20T06:39:31Z master 935d0b3d05) [x86_64-linux]
Description
Running the following script on master(935d0b3d05dfc8b30bba505792129bf0e33ebe3b),
A
appears three times in the lookup chain of C
and A#foo
is called multiple
times with super
.
module A
def foo
[:a] + super
end
end
module B
def foo
[:b] + super
end
end
class Object
def foo
[:object]
end
end
module C
def foo
[:c] + super
end
end
class D
prepend A
include C
include B
def foo
[:d] + super
end
end
B.include A
C.include A
p D.ancestors
p D.new.foo
p RUBY_REVISION
__END__
[A, D, B, A, C, A, Object, Kernel, BasicObject]
[:a, :d, :b, :a, :c, :a, :object]
"935d0b3d05dfc8b30bba505792129bf0e33ebe3b"
This change was introduced in #9573. Is this behavior intentional?
In my opinion it's a bit odd since it's not possible to have duplicates
in the lookup chain on released versions. Allowing duplicates can
surprise peopole that are used to not having duplicates and lead to bugs.
If A#foo
had side effects, for example, calling it multiple times
could be undesirable.
Also, logically it doesn't make sense to have a module be the ancestor of itself.
Comparison operators make less sense with this new setup.
Actions
Like0
Like0Like0Like0Like0Like0