Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6587,23 +6587,24 @@ object Types extends TypeUtils {
class TypeSizeAccumulator(using Context) extends TypeAccumulator[Int] {
var seen = util.HashSet[Type](initialCapacity = 8)
def apply(n: Int, tp: Type): Int =
if seen.contains(tp) then n
else {
seen += tp
tp match {
case tp: AppliedType =>
val tpNorm = tp.tryNormalize
if tpNorm.exists then apply(n, tpNorm)
else foldOver(n + 1, tp)
case tp: RefinedType =>
foldOver(n + 1, tp)
case tp: TypeRef if tp.info.isTypeAlias =>
apply(n, tp.superType)
case tp: TypeParamRef =>
apply(n, TypeComparer.bounds(tp))
case _ =>
tp match {
case tp: AppliedType =>
val tpNorm = tp.tryNormalize
if tpNorm.exists then apply(n, tpNorm)
else foldOver(n + 1, tp)
case tp: RefinedType =>
foldOver(n + 1, tp)
case tp: TypeRef if tp.info.isTypeAlias =>
apply(n, tp.superType)
case tp: TypeParamRef =>
apply(n, TypeComparer.bounds(tp))
case tp: LazyRef =>
if seen.contains(tp) then n
else
seen += tp
foldOver(n, tp)
}
case _ =>
foldOver(n, tp)
}
}

Expand Down
13 changes: 12 additions & 1 deletion project/Build.scala
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,17 @@ object Build {
recur(lines, false)
}

// Hotfix for JDK 8
def replaceJDK11APIs(lines: List[String], file: File): List[String] = {
if (file.getName == "InlayHints.scala") {
lines.map{
_.replace(".repeat(naiveIndent)", " * naiveIndent")
}
} else {
lines
}
}

/** replace imports of `com.google.protobuf.*` with compiler implemented version */
def replaceProtobuf(lines: List[String]): List[String] = {
def recur(ls: List[String]): List[String] = ls match {
Expand Down Expand Up @@ -1271,7 +1282,7 @@ object Build {
val mtagsSharedSources = (targetDir ** "*.scala").get.toSet
mtagsSharedSources.foreach(f => {
val lines = IO.readLines(f)
val substitutions = (replaceProtobuf(_)) andThen (insertUnsafeNullsImport(_))
val substitutions = (replaceProtobuf(_)) andThen (insertUnsafeNullsImport(_)) andThen (replaceJDK11APIs(_, f))
IO.writeLines(f, substitutions(lines))
})
mtagsSharedSources
Expand Down
5 changes: 5 additions & 0 deletions tests/neg/i15692.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
trait TC[X]
object TC {
given [T, S <: TC[S]](using TC[S]): TC[T] = ???
summon[TC[Int]] // error
}
24 changes: 24 additions & 0 deletions tests/pos/i15692.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
sealed trait Nat
sealed trait Succ[Prev <: Nat] extends Nat
sealed trait Zero extends Nat

class Sum[M <: Nat, N <: Nat] {
type Out <: Nat
}

object Sum {
type Aux[M <: Nat, N <: Nat, R <: Nat] = Sum[M, N] { type Out = R }

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

object Test {
def main(args: Array[String]): Unit = {
type _3 = Succ[Succ[Succ[Zero]]]
type _5 = Succ[Succ[_3]]

implicitly[Sum[_3, _5]]
}
}
Loading