Project

General

Profile

Actions

Bug #14704

closed

Module#ancestors looks wrong when a module is both included and prepended in the same class.

Added by knknkn1162 (Kenta Nakajima) about 6 years ago. Updated over 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.6.0dev (2018-04-20 trunk 63212) [x86_64-darwin17]
[ruby-core:86631]
Tags:

Description

Module#ancestors looks wrong when a module is both included and prepended in the same class.
Here is the example script:

module M3; end
module M1
  include M3
end

module M2
  prepend M3
end


class Sub
  include M1
  include M2
end

# [Sub, M1, M3, M2, Object, Kernel, BasicObject]
p Sub.ancestors

The output is expected to be [Sub, M2, M1, M3, Object, Kernel, BasicObject] or [Sub, M3, M2, M1, Object, Kernel, BasicObject] or [Sub, M3, M2, M1, M3, Object, Kernel, BasicObject], but the actual is [Sub, M1, M3, M2, Object, Kernel, BasicObject].

When the M1 and M2 module aren't included or prepended at all like the below script, the result is [Sub, M2, M1, Object, Kernel, BasicObject]. In the first example, the position of the M2 module seems to be wrong.

module M1; end
module M2; end

class Sub
  include M1
  include M2
end

# [Sub, M2, M1, Object, Kernel, BasicObject]
p Sub.ancestors

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #7844: include/prepend satisfiable module dependencies are not satisfiedClosedmatz (Yukihiro Matsumoto)Actions
Actions

Also available in: Atom PDF

Like0
Like0Like0