Skip to content

Commit 068bf4e

Browse files
authored
Merge pull request #602 from scala/backport-lts-3.3-20459
Backport "Only check seen for LazyRef for TypeSizeAccumulator" to 3.3 LTS
2 parents b992ab2 + 906c755 commit 068bf4e

File tree

4 files changed

+58
-17
lines changed

4 files changed

+58
-17
lines changed

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

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6587,23 +6587,24 @@ object Types extends TypeUtils {
65876587
class TypeSizeAccumulator(using Context) extends TypeAccumulator[Int] {
65886588
var seen = util.HashSet[Type](initialCapacity = 8)
65896589
def apply(n: Int, tp: Type): Int =
6590-
if seen.contains(tp) then n
6591-
else {
6592-
seen += tp
6593-
tp match {
6594-
case tp: AppliedType =>
6595-
val tpNorm = tp.tryNormalize
6596-
if tpNorm.exists then apply(n, tpNorm)
6597-
else foldOver(n + 1, tp)
6598-
case tp: RefinedType =>
6599-
foldOver(n + 1, tp)
6600-
case tp: TypeRef if tp.info.isTypeAlias =>
6601-
apply(n, tp.superType)
6602-
case tp: TypeParamRef =>
6603-
apply(n, TypeComparer.bounds(tp))
6604-
case _ =>
6590+
tp match {
6591+
case tp: AppliedType =>
6592+
val tpNorm = tp.tryNormalize
6593+
if tpNorm.exists then apply(n, tpNorm)
6594+
else foldOver(n + 1, tp)
6595+
case tp: RefinedType =>
6596+
foldOver(n + 1, tp)
6597+
case tp: TypeRef if tp.info.isTypeAlias =>
6598+
apply(n, tp.superType)
6599+
case tp: TypeParamRef =>
6600+
apply(n, TypeComparer.bounds(tp))
6601+
case tp: LazyRef =>
6602+
if seen.contains(tp) then n
6603+
else
6604+
seen += tp
66056605
foldOver(n, tp)
6606-
}
6606+
case _ =>
6607+
foldOver(n, tp)
66076608
}
66086609
}
66096610

project/Build.scala

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,17 @@ object Build {
597597
recur(lines, false)
598598
}
599599

600+
// Hotfix for JDK 8
601+
def replaceJDK11APIs(lines: List[String], file: File): List[String] = {
602+
if (file.getName == "InlayHints.scala") {
603+
lines.map{
604+
_.replace(".repeat(naiveIndent)", " * naiveIndent")
605+
}
606+
} else {
607+
lines
608+
}
609+
}
610+
600611
/** replace imports of `com.google.protobuf.*` with compiler implemented version */
601612
def replaceProtobuf(lines: List[String]): List[String] = {
602613
def recur(ls: List[String]): List[String] = ls match {
@@ -1271,7 +1282,7 @@ object Build {
12711282
val mtagsSharedSources = (targetDir ** "*.scala").get.toSet
12721283
mtagsSharedSources.foreach(f => {
12731284
val lines = IO.readLines(f)
1274-
val substitutions = (replaceProtobuf(_)) andThen (insertUnsafeNullsImport(_))
1285+
val substitutions = (replaceProtobuf(_)) andThen (insertUnsafeNullsImport(_)) andThen (replaceJDK11APIs(_, f))
12751286
IO.writeLines(f, substitutions(lines))
12761287
})
12771288
mtagsSharedSources

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: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
sealed trait Nat
2+
sealed trait Succ[Prev <: Nat] extends Nat
3+
sealed trait Zero extends Nat
4+
5+
class Sum[M <: Nat, N <: Nat] {
6+
type Out <: Nat
7+
}
8+
9+
object Sum {
10+
type Aux[M <: Nat, N <: Nat, R <: Nat] = Sum[M, N] { type Out = R }
11+
12+
implicit def sum0[N <: Nat]: Sum.Aux[Zero, N, N] = new Sum[Zero, N] { type Out = N }
13+
implicit def sum1[M <: Nat, N <: Nat, R <: Nat](implicit sum: Sum.Aux[M, Succ[N], R]): Sum.Aux[Succ[M], N, R] =
14+
new Sum[Succ[M], N] { type Out = R }
15+
}
16+
17+
object Test {
18+
def main(args: Array[String]): Unit = {
19+
type _3 = Succ[Succ[Succ[Zero]]]
20+
type _5 = Succ[Succ[_3]]
21+
22+
implicitly[Sum[_3, _5]]
23+
}
24+
}

0 commit comments

Comments
 (0)