Skip to content

Commit 7e63af3

Browse files
committed
Merge pull request #979 from dotty-staging/fix/hk-deep-subtype-2
TypeComparer: delay looking up members of AndTypes
2 parents 80eb242 + 6e4b4f4 commit 7e63af3

File tree

2 files changed

+14
-10
lines changed

2 files changed

+14
-10
lines changed

src/dotty/tools/dotc/core/TypeComparer.scala

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -331,17 +331,23 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
331331
}
332332
comparePolyParam
333333
case tp2: RefinedType =>
334+
def compareRefinedSlow: Boolean = {
335+
val name2 = tp2.refinedName
336+
isSubType(tp1, tp2.parent) &&
337+
(name2 == nme.WILDCARD || hasMatchingMember(name2, tp1, tp2))
338+
}
334339
def compareRefined: Boolean = {
335340
val tp1w = tp1.widen
336341
val skipped2 = skipMatching(tp1w, tp2)
337342
if ((skipped2 eq tp2) || !Config.fastPathForRefinedSubtype) {
338-
val name2 = tp2.refinedName
339-
val normalPath =
340-
isSubType(tp1, tp2.parent) &&
341-
( name2 == nme.WILDCARD
342-
|| hasMatchingMember(name2, tp1, tp2)
343-
|| fourthTry(tp1, tp2)
344-
)
343+
val normalPath = tp1 match {
344+
case tp1: AndType =>
345+
// Delay calling `compareRefinedSlow` because looking up a member
346+
// of an `AndType` can lead to a cascade of subtyping checks
347+
fourthTry(tp1, tp2) || compareRefinedSlow
348+
case _ =>
349+
compareRefinedSlow || fourthTry(tp1, tp2)
350+
}
345351
normalPath ||
346352
needsEtaLift(tp1, tp2) && tp1.testLifted(tp2.typeParams, isSubType(_, tp2), classBounds(tp2))
347353
}

test/dotc/scala-collections.whitelist

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -286,9 +286,7 @@
286286
./scala-scala/src/library/scala/collection/generic/SortedMapFactory.scala
287287
./scala-scala/src/library/scala/collection/generic/SortedSetFactory.scala
288288
./scala-scala/src/library/scala/collection/generic/SetFactory.scala
289-
290-
# deep subtype
291-
#./scala-scala/src/library/scala/collection/generic/ParFactory.scala
289+
./scala-scala/src/library/scala/collection/generic/ParFactory.scala
292290

293291
# https://github.com/lampepfl/dotty/issues/974
294292
#./scala-scala/src/library/scala/collection/generic/MutableSortedSetFactory.scala

0 commit comments

Comments
 (0)