Skip to content

Commit 9d5bb69

Browse files
eejbyfeldttgodzik
authored andcommitted
Do seen check only for LazyRef
Also adds test case that stackoverflows without any seen check. [Cherry-picked 008d58e]
1 parent 4f31f01 commit 9d5bb69

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
@@ -6585,7 +6585,9 @@ object Types extends TypeUtils {
65856585
}
65866586

65876587
class TypeSizeAccumulator(using Context) extends TypeAccumulator[Int] {
6588+
var seen = util.HashSet[Type](initialCapacity = 8)
65886589
def apply(n: Int, tp: Type): Int =
6590+
seen += tp
65896591
tp match {
65906592
case tp: AppliedType =>
65916593
val tpNorm = tp.tryNormalize
@@ -6597,6 +6599,8 @@ object Types extends TypeUtils {
65976599
apply(n, tp.superType)
65986600
case tp: TypeParamRef =>
65996601
apply(n, TypeComparer.bounds(tp))
6602+
case tp: LazyRef if seen.contains(tp) =>
6603+
n
66006604
case _ =>
66016605
foldOver(n, tp)
66026606
}

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)