Skip to content

Commit 49d4601

Browse files
committed
isSubtype: try to dealias TypeRefs before recursively checking the prefixes
As demonstrated by tests/pos/hk-deep-subtype.scala, we can avoid some deep subtype recursions that result in stack overflows by doing this.
1 parent 4463f5e commit 49d4601

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
153153
tp1 match {
154154
case tp1: NamedType =>
155155
val sym1 = tp1.symbol
156+
compareAlias(tp1.info) ||
156157
(if ((sym1 ne NoSymbol) && (sym1 eq tp2.symbol))
157158
ctx.erasedTypes || sym1.isStaticOwner || isSubType(tp1.prefix, tp2.prefix)
158159
else
@@ -163,8 +164,7 @@ class TypeComparer(initctx: Context) extends DotClass with ConstraintHandling {
163164
!tp2.isInstanceOf[WithFixedSym]
164165
) ||
165166
compareHK(tp1, tp2, inOrder = true) ||
166-
compareHK(tp2, tp1, inOrder = false) ||
167-
compareAlias(tp1.info)
167+
compareHK(tp2, tp1, inOrder = false)
168168
case _ =>
169169
compareHK(tp2, tp1, inOrder = false) ||
170170
compareAlias(NoType)

test/dotc/scala-collections.whitelist

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,7 @@
263263
./scala-scala/src/library/scala/collection/generic/GenericSeqCompanion.scala
264264
./scala-scala/src/library/scala/collection/generic/GenericSetTemplate.scala
265265

266-
# deep subtype
267-
#./scala-scala/src/library/scala/collection/generic/GenericTraversableTemplate.scala
266+
./scala-scala/src/library/scala/collection/generic/GenericTraversableTemplate.scala
268267

269268
./scala-scala/src/library/scala/collection/generic/HasNewBuilder.scala
270269
./scala-scala/src/library/scala/collection/generic/HasNewCombiner.scala

tests/pos/hk-deep-subtype.scala

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// Minimized from scala.collection.generic.GenTraversableFactory plus dependencies
2+
import scala.annotation.unchecked.uncheckedVariance
3+
4+
trait GT[A] extends GTT[A, GT]
5+
6+
trait HNB[B]
7+
trait GTT[+C, DD[X] <: GT[X]] extends HNB[DD[C] @uncheckedVariance] // Can be any annotation and still crash
8+
9+
class GTF[EE[X] <: GT[X] with GTT[X, EE]]
10+
{
11+
def foo[F]: EE[F] = ???
12+
def bar[G](f: G): EE[G] = ???
13+
14+
def tabulate: EE[EE[Int]] = bar(foo)
15+
}

0 commit comments

Comments
 (0)