Skip to content

Commit 2849aed

Browse files
Merge pull request #14259 from dotty-staging/fix-overly-lazy-normalization
Fix #7512: Normalize type arguments before instantiation
2 parents 190a982 + df18652 commit 2849aed

File tree

3 files changed

+26
-1
lines changed

3 files changed

+26
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4171,7 +4171,7 @@ object Types {
41714171
case MatchAlias(alias) =>
41724172
trace(i"normalize $this", typr, show = true) {
41734173
MatchTypeTrace.recurseWith(this) {
4174-
alias.applyIfParameterized(args).tryNormalize
4174+
alias.applyIfParameterized(args.map(_.normalized)).tryNormalize
41754175
}
41764176
}
41774177
case _ =>

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, 10)
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)