Skip to content

Commit 035bff6

Browse files
Fix scala#7512: Normalize arguments before instantiation
The newly added test is blacklisted for pickling tests because the after pickler code path doesn't go thought TypeApplications and keeps types un-normalized, albeit equivalant to their before pickling counterparts.
1 parent 84b26ac commit 035bff6

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ class TypeApplications(val self: Type) extends AnyVal {
342342
}
343343
if ((dealiased eq stripped) || followAlias)
344344
try {
345-
val instantiated = dealiased.instantiate(args)
345+
val instantiated = dealiased.instantiate(args.map(_.simplified))
346346
if (followAlias) instantiated.normalized else instantiated
347347
}
348348
catch { case ex: IndexOutOfBoundsException => AppliedType(self, args) }

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ i9999.scala
3939
9757.scala
4040
9890.scala
4141
13491.scala
42+
7512.scala
4243

4344
# Opaque type
4445
i5720.scala

tests/pos/7512.scala

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import scala.compiletime.ops.int.S
2+
3+
object InfiniteLoopMatchType {
4+
def main(args: Array[String]): Unit = {
5+
testProd(2, 5)
6+
}
7+
8+
def testProd(a: Int, b: Int)(using ev: (a.type * b.type) =:= (b.type * a.type)) = true
9+
10+
type *[A <: Int, B <: Int] <: Int = A match {
11+
case 0 => 0
12+
case _ => MultiplyLoop[A, B, 0]
13+
}
14+
15+
type MultiplyLoop[A <: Int, B <: Int, Acc <: Int] <: Int = A match {
16+
case 0 => Acc
17+
case S[aMinusOne] => MultiplyLoop[aMinusOne, B, B + Acc]
18+
}
19+
20+
type +[A <: Int, B <: Int] <: Int = A match {
21+
case 0 => B
22+
case S[aMinusOne] => aMinusOne + S[B]
23+
}
24+
}

0 commit comments

Comments
 (0)