Skip to content

Commit 59f7b7e

Browse files
authored
Merge pull request #12250 from dotty-staging/fix-12050
Fix #12050: catch StackOverflow in tryNormalize
2 parents c9d2826 + 11c683f commit 59f7b7e

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4550,7 +4550,12 @@ object Types {
45504550
private var myReduced: Type = null
45514551
private var reductionContext: util.MutableMap[Type, Type] = null
45524552

4553-
override def tryNormalize(using Context): Type = reduced.normalized
4553+
override def tryNormalize(using Context): Type =
4554+
try
4555+
reduced.normalized
4556+
catch
4557+
case ex: Throwable =>
4558+
handleRecursive("normalizing", s"${scrutinee.show} match ..." , ex)
45544559

45554560
def reduced(using Context): Type = {
45564561

tests/neg/12050.scala

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
class P[X, Y]
2+
3+
type Swap[X] = X match
4+
case P[x, y] => Swap[P[y, x]]
5+
6+
val z: P[String, Int] = ??? : Swap[P[Int, String]] // error
7+
// ^
8+
// Recursion limit exceeded.
9+
// Maybe there is an illegal cyclic reference?
10+
// If that's not the case, you could also try to increase the stacksize using the -Xss JVM option.
11+
// A recurring operation is (inner to outer):
12+
//
13+
// normalizing P[String, Int] match ...
14+
// normalizing P[Int, String] match ...
15+
// normalizing P[String, Int] match ...
16+
// normalizing P[Int, String] match ...
17+
// normalizing P[String, Int] match ...
18+
// normalizing P[Int, String] match ...
19+
// normalizing P[String, Int] match ...
20+
// normalizing P[Int, String] match ...
21+
// normalizing P[String, Int] match ...
22+
// normalizing P[Int, String] match ...
23+
// ...
24+
//
25+
// normalizing P[String, Int] match ...
26+
// normalizing P[Int, String] match ...
27+
// normalizing P[String, Int] match ...
28+
// normalizing P[Int, String] match ...
29+
// normalizing P[String, Int] match ...
30+
// normalizing P[Int, String] match ...
31+
// normalizing P[String, Int] match ...
32+
// normalizing P[Int, String] match ...
33+
// normalizing P[String, Int] match ...
34+
// normalizing P[Int, String] match ...

0 commit comments

Comments
 (0)