Skip to content

Commit f7abc2d

Browse files
eejbyfeldtWojciechMazur
authored andcommitted
Do seen check only for LazyRef
Also adds test case that stackoverflows without any seen check. [Cherry-picked 008d58e]
1 parent 551b464 commit f7abc2d

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
@@ -7022,7 +7022,9 @@ object Types extends TypeUtils {
70227022
}
70237023

70247024
class TypeSizeAccumulator(using Context) extends TypeAccumulator[Int] {
7025+
var seen = util.HashSet[Type](initialCapacity = 8)
70257026
def apply(n: Int, tp: Type): Int =
7027+
seen += tp
70267028
tp match {
70277029
case tp: AppliedType =>
70287030
val tpNorm = tp.tryNormalize
@@ -7034,6 +7036,8 @@ object Types extends TypeUtils {
70347036
apply(n, tp.superType)
70357037
case tp: TypeParamRef =>
70367038
apply(n, TypeComparer.bounds(tp))
7039+
case tp: LazyRef if seen.contains(tp) =>
7040+
n
70377041
case _ =>
70387042
foldOver(n, tp)
70397043
}

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)