Skip to content

Commit e4c60b4

Browse files
committed
Do seen check only for LazyRef
Also adds test case that stackoverflows without any seen check.
1 parent 7a94718 commit e4c60b4

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
@@ -6974,7 +6974,9 @@ object Types extends TypeUtils {
69746974
}
69756975

69766976
class TypeSizeAccumulator(using Context) extends TypeAccumulator[Int] {
6977+
var seen = util.HashSet[Type](initialCapacity = 8)
69776978
def apply(n: Int, tp: Type): Int =
6979+
seen += tp
69786980
tp match {
69796981
case tp: AppliedType =>
69806982
val tpNorm = tp.tryNormalize
@@ -6986,6 +6988,8 @@ object Types extends TypeUtils {
69866988
apply(n, tp.superType)
69876989
case tp: TypeParamRef =>
69886990
apply(n, TypeComparer.bounds(tp))
6991+
case tp: LazyRef if seen.contains(tp) =>
6992+
n
69896993
case _ =>
69906994
foldOver(n, tp)
69916995
}

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)