Project

General

Profile

Actions

Feature #14365

open

irreconcilable ancestor chain ordering expectations should perhaps produce an error

Added by bughit (bug hit) almost 7 years ago. Updated over 5 years ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:84895]

Description

module Module1
  def foo
    puts 'Module1#foo'
    super
  end
end

module Module2
  include Module1
  
  def foo
    puts 'Module2#foo'
    super
  end
end

class SuperClass1
  def foo
    puts "SuperClass1#foo"
  end
end

class SubClass1 < SuperClass1
  include Module2
  include Module1
  
  def foo
    puts "SubClass1#foo"
    super
  end
end

p SubClass1.ancestors

SubClass1.new.foo

If you look at SubClass1 in isolation, the expectation is that Module1 will be in front of Module2
If you look at Module2 in isolation, the expectation is that Module2 will be in front of Module1

these can not be reconciled, Module2 wins, but would it not be better if this were an error? Forcing you to write:

class SubClass1 < SuperClass1
  include Module1
  include Module2
  
  def foo
    puts "SubClass1#foo"
    super
  end
end
Actions

Also available in: Atom PDF

Like0
Like0Like0