Skip to content

Commit bb772f3

Browse files
Backport "Fix #17115: Try to normalize while computing typeSize." to LTS (#20665)
Backports #18386 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents 747a473 + 6f194ed commit bb772f3

File tree

4 files changed

+52
-1
lines changed

4 files changed

+52
-1
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -6397,7 +6397,9 @@ object Types {
63976397
seen += tp
63986398
tp match {
63996399
case tp: AppliedType =>
6400-
foldOver(n + 1, tp)
6400+
val tpNorm = tp.tryNormalize
6401+
if tpNorm.exists then apply(n, tpNorm)
6402+
else foldOver(n + 1, tp)
64016403
case tp: RefinedType =>
64026404
foldOver(n + 1, tp)
64036405
case tp: TypeRef if tp.info.isTypeAlias =>

compiler/test/dotc/pos-test-pickling.blacklist

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ i6505.scala
5454
i15158.scala
5555
i15155.scala
5656
i15827.scala
57+
i18211.scala
5758

5859
# Opaque type
5960
i5720.scala

tests/pos/i17115.scala

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait A[T <: Tuple] { val x: Int }
2+
given empty: A[EmptyTuple] with { val x = 1 }
3+
given inductive[Tup <: NonEmptyTuple](using A[Tuple.Tail[Tup]]): A[Tup] with { val x = summon[A[Tuple.Tail[Tup]]].x + 1 }
4+
5+
object Test:
6+
def main(args: Array[String]): Unit =
7+
println(summon[A[(String, String, String)]].x) //this line is fine
8+
println(summon[A[(String, String, String, String)]].x) //this line gives error
9+
end Test

tests/pos/i18211.scala

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import scala.compiletime.ops.int.*
2+
3+
type AnyInt[A <: Int] <: Int = A match {
4+
case _ => A
5+
}
6+
7+
type IndexOf[A, T <: Tuple] <: Int = T match {
8+
case EmptyTuple => -1
9+
case A *: t => 0
10+
case _ *: t =>
11+
IndexOf[A, t] match {
12+
case -1 => -1
13+
case AnyInt[a] => S[a]
14+
}
15+
}
16+
17+
type Indexes[A, T <: Tuple]
18+
object Indexes {
19+
given of[A, T <: Tuple](using IndexOf[A, T] >= 0 =:= true)(using
20+
index: ValueOf[IndexOf[A, T]],
21+
next: Indexes[A, Tuple.Drop[T, S[IndexOf[A, T]]]]
22+
): Indexes[A, T] = ???
23+
24+
given empty[A, T <: Tuple](using IndexOf[A, T] =:= -1): Indexes[A, T] = ???
25+
}
26+
27+
class GetAll[A]:
28+
def apply[T <: Tuple](t: T)(using indexes: Indexes[A, T]): List[A] = ???
29+
30+
def getAll[A]: GetAll[A] = new GetAll[A]
31+
32+
def test =
33+
// the code here is trying to get all values from a tuple that has type [X] as a list
34+
35+
// this works if there are only two strings in the tuple
36+
getAll[String](("str1", 1, "str2", false))
37+
38+
//but this not compiles if there are more than two strings in the tuple
39+
getAll[String](("str1", 1, "str2", false, "str3"))

0 commit comments

Comments
 (0)