Skip to content

Commit 008d58e

Browse files
committed
Do seen check only for LazyRef
Also adds test case that stackoverflows without any seen check.
1 parent c2ef180 commit 008d58e

File tree

3 files changed

+10
-1
lines changed

3 files changed

+10
-1
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7044,7 +7044,9 @@ object Types extends TypeUtils {
70447044
}
70457045

70467046
class TypeSizeAccumulator(using Context) extends TypeAccumulator[Int] {
7047+
var seen = util.HashSet[Type](initialCapacity = 8)
70477048
def apply(n: Int, tp: Type): Int =
7049+
seen += tp
70487050
tp match {
70497051
case tp: AppliedType =>
70507052
val tpNorm = tp.tryNormalize
@@ -7056,6 +7058,8 @@ object Types extends TypeUtils {
70567058
apply(n, tp.superType)
70577059
case tp: TypeParamRef =>
70587060
apply(n, TypeComparer.bounds(tp))
7061+
case tp: LazyRef if seen.contains(tp) =>
7062+
n
70597063
case _ =>
70607064
foldOver(n, tp)
70617065
}

tests/neg/i15692.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
trait TC[X]
2+
object TC {
3+
given [T, S <: TC[S]](using TC[S]): TC[T] = ???
4+
summon[TC[Int]] // error
5+
}

tests/pos/i15692.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Sum[M <: Nat, N <: Nat] {
99
object Sum {
1010
type Aux[M <: Nat, N <: Nat, R <: Nat] = Sum[M, N] { type Out = R }
1111

12-
implicit def sum0[N <: Nat]: Sum.Aux[Zero, N, N] = new Sum[Zero, N] { type Out = N }
12+
implicit def sum0[N <: Nat]: Sum.Aux[Zero, N, N] = new Sum[Zero, N] { type Out = N }
1313
implicit def sum1[M <: Nat, N <: Nat, R <: Nat](implicit sum: Sum.Aux[M, Succ[N], R]): Sum.Aux[Succ[M], N, R] =
1414
new Sum[Succ[M], N] { type Out = R }
1515
}

0 commit comments

Comments
 (0)