diff --git a/compiler/src/dotty/tools/dotc/core/Types.scala b/compiler/src/dotty/tools/dotc/core/Types.scala index 8a0b0f12c167..718abc9aeb8f 100644 --- a/compiler/src/dotty/tools/dotc/core/Types.scala +++ b/compiler/src/dotty/tools/dotc/core/Types.scala @@ -4525,7 +4525,12 @@ object Types { private var myReduced: Type = null private var reductionContext: util.MutableMap[Type, Type] = null - override def tryNormalize(using Context): Type = reduced.normalized + override def tryNormalize(using Context): Type = + try + reduced.normalized + catch + case ex: Throwable => + handleRecursive("normalizing", s"${scrutinee.show} match ..." , ex) def reduced(using Context): Type = { diff --git a/tests/neg/12050.scala b/tests/neg/12050.scala new file mode 100644 index 000000000000..a8e073bb353b --- /dev/null +++ b/tests/neg/12050.scala @@ -0,0 +1,34 @@ +class P[X, Y] + +type Swap[X] = X match + case P[x, y] => Swap[P[y, x]] + +val z: P[String, Int] = ??? : Swap[P[Int, String]] // error +// ^ +// Recursion limit exceeded. +// Maybe there is an illegal cyclic reference? +// If that's not the case, you could also try to increase the stacksize using the -Xss JVM option. +// A recurring operation is (inner to outer): +// +// normalizing P[String, Int] match ... +// normalizing P[Int, String] match ... +// normalizing P[String, Int] match ... +// normalizing P[Int, String] match ... +// normalizing P[String, Int] match ... +// normalizing P[Int, String] match ... +// normalizing P[String, Int] match ... +// normalizing P[Int, String] match ... +// normalizing P[String, Int] match ... +// normalizing P[Int, String] match ... +// ... +// +// normalizing P[String, Int] match ... +// normalizing P[Int, String] match ... +// normalizing P[String, Int] match ... +// normalizing P[Int, String] match ... +// normalizing P[String, Int] match ... +// normalizing P[Int, String] match ... +// normalizing P[String, Int] match ... +// normalizing P[Int, String] match ... +// normalizing P[String, Int] match ... +// normalizing P[Int, String] match ...