Skip to content

Commit 65748a8

Browse files
EugeneFlesselleWojciechMazur
authored andcommitted
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]
1 parent f981f58 commit 65748a8

File tree

5 files changed

+39
-1
lines changed

5 files changed

+39
-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
@@ -4695,7 +4695,7 @@ object Types extends TypeUtils {
46954695
case AliasingBounds(alias) if isMatchAlias =>
46964696
trace(i"normalize $this", typr, show = true) {
46974697
MatchTypeTrace.recurseWith(this) {
4698-
alias.applyIfParameterized(args.map(_.normalized)).tryNormalize
4698+
alias.applyIfParameterized(args).tryNormalize
46994699
/* `applyIfParameterized` may reduce several HKTypeLambda applications
47004700
* before the underlying MatchType is reached.
47014701
* Even if they do not involve any match type normalizations yet,

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)