Skip to content

Commit 2ad16cd

Browse files
authored
Fix #17115: Try to normalize while computing typeSize. (#18386)
2 parents d482108 + eb18e53 commit 2ad16cd

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
@@ -6465,7 +6465,9 @@ object Types {
64656465
seen += tp
64666466
tp match {
64676467
case tp: AppliedType =>
6468-
foldOver(n + 1, tp)
6468+
val tpNorm = tp.tryNormalize
6469+
if tpNorm.exists then apply(n, tpNorm)
6470+
else foldOver(n + 1, tp)
64696471
case tp: RefinedType =>
64706472
foldOver(n + 1, tp)
64716473
case tp: TypeRef if tp.info.isTypeAlias =>

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

+1
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ i15827.scala
6060
i17149.scala
6161
tuple-fold.scala
6262
mt-redux-norm.perspective.scala
63+
i18211.scala
6364

6465
# Opaque type
6566
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)