@@ -512,12 +512,27 @@ object RefChecks {
512512 override def matches (sym1 : Symbol , sym2 : Symbol ): Boolean =
513513 considerMatching(sym1, sym2, self)
514514
515- // We can exclude pairs safely from checking only of they also matched in
516- // the parent class. See neg/i12828.scala for an example where this matters.
515+ private def inLinearizationOrder (sym1 : Symbol , sym2 : Symbol , parent : Symbol ): Boolean =
516+ val owner1 = sym1.owner
517+ val owner2 = sym2.owner
518+ def precedesIn (bcs : List [ClassSymbol ]): Boolean = (bcs : @ unchecked) match
519+ case bc :: bcs1 =>
520+ if owner1 eq bc then true
521+ else if owner2 eq bc then false
522+ else precedesIn(bcs1)
523+ case _ =>
524+ false
525+ precedesIn(parent.asClass.baseClasses)
526+
527+ // We can exclude pairs safely from checking only under two additional conditions
528+ // - their signatures also match in the parent class.
529+ // See neg/i12828.scala for an example where this matters.
530+ // - They overriding/overridden appear in linearization order.
531+ // See neg/i5094.scala for an example where this matters.
517532 override def canBeHandledByParent (sym1 : Symbol , sym2 : Symbol , parent : Symbol ): Boolean =
518533 considerMatching(sym1, sym2, parent.thisType)
519534 .showing(i " already handled ${sym1.showLocated}: ${sym1.asSeenFrom(parent.thisType).signature}, ${sym2.showLocated}: ${sym2.asSeenFrom(parent.thisType).signature} = $result" , refcheck)
520- && super .canBeHandledByParent (sym1, sym2, parent)
535+ && inLinearizationOrder (sym1, sym2, parent)
521536 end opc
522537
523538 while opc.hasNext do
0 commit comments