From df18652deb260df9c057709c9bd3a8921fbe9e4e Mon Sep 17 00:00:00 2001 From: Olivier Blanvillain Date: Wed, 12 Jan 2022 22:57:10 +0100 Subject: [PATCH] Fix #7512: Normalize match type arguments 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. --- .../src/dotty/tools/dotc/core/Types.scala | 2 +- .../test/dotc/pos-test-pickling.blacklist | 1 + tests/pos/7512.scala | 24 +++++++++++++++++++ 3 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 tests/pos/7512.scala diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 2d02546a6d5e..b090682a4cd1 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -4171,7 +4171,7 @@ object Types { case MatchAlias(alias) => trace(i"normalize $this", typr, show = true) { MatchTypeTrace.recurseWith(this) { - alias.applyIfParameterized(args).tryNormalize + alias.applyIfParameterized(args.map(_.normalized)).tryNormalize } } case _ => diff --git a/compiler/test/dotc/pos-test-pickling.blacklist b/compiler/test/dotc/pos-test-pickling.blacklist index c913933c6537..b42d41f0df85 100644 --- a/compiler/test/dotc/pos-test-pickling.blacklist +++ b/compiler/test/dotc/pos-test-pickling.blacklist @@ -39,6 +39,7 @@ i9999.scala 9757.scala 9890.scala 13491.scala +7512.scala # Opaque type i5720.scala diff --git a/tests/pos/7512.scala b/tests/pos/7512.scala new file mode 100644 index 000000000000..fbc8ae6a72e3 --- /dev/null +++ b/tests/pos/7512.scala @@ -0,0 +1,24 @@ +import scala.compiletime.ops.int.S + +object InfiniteLoopMatchType { + def main(args: Array[String]): Unit = { + testProd(2, 10) + } + + def testProd(a: Int, b: Int)(using ev: (a.type * b.type) =:= (b.type * a.type)) = true + + type *[A <: Int, B <: Int] <: Int = A match { + case 0 => 0 + case _ => MultiplyLoop[A, B, 0] + } + + type MultiplyLoop[A <: Int, B <: Int, Acc <: Int] <: Int = A match { + case 0 => Acc + case S[aMinusOne] => MultiplyLoop[aMinusOne, B, B + Acc] + } + + type +[A <: Int, B <: Int] <: Int = A match { + case 0 => B + case S[aMinusOne] => aMinusOne + S[B] + } +}