Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport "Fix #17115: Try to normalize while computing typeSize." to LTS #20665

Merged
merged 2 commits into from
Jun 20, 2024
Merged
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
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/core/Types.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6397,7 +6397,9 @@ object Types {
seen += tp
tp match {
case tp: AppliedType =>
foldOver(n + 1, tp)
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 =>
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotc/pos-test-pickling.blacklist
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ i6505.scala
i15158.scala
i15155.scala
i15827.scala
i18211.scala

# Opaque type
i5720.scala
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/i17115.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
trait A[T <: Tuple] { val x: Int }
given empty: A[EmptyTuple] with { val x = 1 }
given inductive[Tup <: NonEmptyTuple](using A[Tuple.Tail[Tup]]): A[Tup] with { val x = summon[A[Tuple.Tail[Tup]]].x + 1 }

object Test:
def main(args: Array[String]): Unit =
println(summon[A[(String, String, String)]].x) //this line is fine
println(summon[A[(String, String, String, String)]].x) //this line gives error
end Test
39 changes: 39 additions & 0 deletions tests/pos/i18211.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import scala.compiletime.ops.int.*

type AnyInt[A <: Int] <: Int = A match {
case _ => A
}

type IndexOf[A, T <: Tuple] <: Int = T match {
case EmptyTuple => -1
case A *: t => 0
case _ *: t =>
IndexOf[A, t] match {
case -1 => -1
case AnyInt[a] => S[a]
}
}

type Indexes[A, T <: Tuple]
object Indexes {
given of[A, T <: Tuple](using IndexOf[A, T] >= 0 =:= true)(using
index: ValueOf[IndexOf[A, T]],
next: Indexes[A, Tuple.Drop[T, S[IndexOf[A, T]]]]
): Indexes[A, T] = ???

given empty[A, T <: Tuple](using IndexOf[A, T] =:= -1): Indexes[A, T] = ???
}

class GetAll[A]:
def apply[T <: Tuple](t: T)(using indexes: Indexes[A, T]): List[A] = ???

def getAll[A]: GetAll[A] = new GetAll[A]

def test =
// the code here is trying to get all values from a tuple that has type [X] as a list

// this works if there are only two strings in the tuple
getAll[String](("str1", 1, "str2", false))

//but this not compiles if there are more than two strings in the tuple
getAll[String](("str1", 1, "str2", false, "str3"))
Loading