Skip to content

Commit 50fd96b

Browse files
committed
Drop normalization of applied match alias arguments
Delay their normalization until it is needed. Avoids overflows from infinite match types that did not need to normalize. Also improves MatchTypeTraces as a side effect. It appears to have been added to avoid some separate issue, which seems to have been fixed. It is no longer needed since the previous fix with constant folding in disjointnessBoundary. [Cherry-picked 32752e2][modified]
1 parent 27fe00e commit 50fd96b

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4517,7 +4517,14 @@ object Types extends TypeUtils {
45174517
case MatchAlias(alias) =>
45184518
trace(i"normalize $this", typr, show = true) {
45194519
MatchTypeTrace.recurseWith(this) {
4520-
alias.applyIfParameterized(args.map(_.normalized)).tryNormalize
4520+
alias.applyIfParameterized(args).tryNormalize
4521+
/* `applyIfParameterized` may reduce several HKTypeLambda applications
4522+
* before the underlying MatchType is reached.
4523+
* Even if they do not involve any match type normalizations yet,
4524+
* we still want to record these reductions in the MatchTypeTrace.
4525+
* They should however only be attempted if they eventually expand
4526+
* to a match type, which is ensured by the `isMatchAlias` guard.
4527+
*/
45214528
}
45224529
}
45234530
case _ =>

tests/neg/i12049d.check

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- [E007] Type Mismatch Error: tests/neg/i12049d.scala:14:52 -----------------------------------------------------------
2+
14 |val x: M[NotRelevant[Nothing], Relevant[Nothing]] = 2 // error
3+
| ^
4+
| Found: (2 : Int)
5+
| Required: M[NotRelevant[Nothing], Relevant[Nothing]]
6+
|
7+
| Note: a match type could not be fully reduced:
8+
|
9+
| trying to reduce M[NotRelevant[Nothing], Relevant[Nothing]]
10+
| trying to reduce Relevant[Nothing]
11+
| failed since selector Nothing
12+
| is uninhabited (there are no values of that type).
13+
|
14+
| longer explanation available when compiling with `-explain`

tests/neg/i12049d.scala

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
2+
trait A
3+
trait B
4+
5+
type M[X, Y] = Y match
6+
case A => Int
7+
case B => String
8+
9+
type Relevant[Z] = Z match
10+
case A => B
11+
type NotRelevant[Z] = Z match
12+
case B => A
13+
14+
val x: M[NotRelevant[Nothing], Relevant[Nothing]] = 2 // error
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
type Rec[X] = X match
3+
case Int => Rec[X]
4+
5+
type M[Unused, Y] = Y match
6+
case String => Double
7+
8+
def foo[X](d: M[Rec[X], "hi"]) = ???
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
def Test = foo[Int](3d) // crash before changes

0 commit comments

Comments
 (0)