Skip to content

Commit e819415

Browse files
committed
Apply linearization filter only to refchecks
Apply linearization filter only to refchecks, not to other overriding pairs cursors.
1 parent 8b91b55 commit e819415

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

compiler/src/dotty/tools/dotc/transform/OverridingPairs.scala

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -98,16 +98,7 @@ object OverridingPairs {
9898
* of both symbol's owners? Assumed to be true by default, but overridden in RefChecks.
9999
*/
100100
protected def canBeHandledByParent(sym1: Symbol, sym2: Symbol, parent: Symbol): Boolean =
101-
val owner1 = sym1.owner
102-
val owner2 = sym2.owner
103-
def precedesIn(bcs: List[ClassSymbol]): Boolean = (bcs: @unchecked) match
104-
case bc :: bcs1 =>
105-
if owner1 eq bc then true
106-
else if owner2 eq bc then false
107-
else precedesIn(bcs1)
108-
case _ =>
109-
false
110-
precedesIn(parent.asClass.baseClasses)
101+
true
111102

112103
/** The scope entries that have already been visited as overridden
113104
* (maybe excluded because of already handled by a parent).

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)