Skip to content

Commit 6c81a74

Browse files
authored
Merge pull request #12320 from dotty-staging/fix-matchtype-gc
Don't let caseLambda bindings accumulate in constraint
2 parents d81b0e5 + 80f15c3 commit 6c81a74

File tree

4 files changed

+32
-2
lines changed

4 files changed

+32
-2
lines changed

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

+3-1
Original file line numberDiff line numberDiff line change
@@ -2879,7 +2879,9 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
28792879
if (provablyEmpty(scrut))
28802880
NoType
28812881
else
2882-
recur(cases)
2882+
val savedConstraint = constraint
2883+
try recur(cases)
2884+
finally constraint = savedConstraint // caseLambda additions are dropped
28832885
}
28842886
}
28852887
}

tests/neg/6697.check

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
-- [E057] Type Mismatch Error: tests/neg/6697.scala:6:35 ---------------------------------------------------------------
2+
6 | type Copy[O <: Off] = Of[Sup[O], Sub[O]] // error
3+
| ^
4+
| Type argument Test.Sub[O] does not conform to upper bound Test.Sup[O]
5+
|
6+
| Note: a match type could not be fully reduced:
7+
|
8+
| trying to reduce Test.Sub[O]
9+
| failed since selector O
10+
| matches none of the cases
11+
|
12+
| case Test.Of[sup, sub] => sub
13+
14+
longer explanation available when compiling with `-explain`

tests/pos/6697.scala renamed to tests/neg/6697.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ object Test {
33
case class Of[sup, sub <: sup]() extends Off
44
type Sup[O <: Off] = O match { case Of[sup, sub] => sup }
55
type Sub[O <: Off] = O match { case Of[sup, sub] => sub }
6-
type Copy[O <: Off] = Of[Sup[O], Sub[O]]
6+
type Copy[O <: Off] = Of[Sup[O], Sub[O]] // error
77
}

tests/neg/9107.scala

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
trait M[F[_]]
2+
trait Inv[T]
3+
4+
object Test {
5+
def ev[X] = implicitly[
6+
(X match { case Inv[t] => Int }) =:=
7+
(X match { case Inv[t] => t })
8+
] // error
9+
10+
def ev2[X] = implicitly[
11+
(M[[t] =>> runtime.MatchCase[Inv[t], Int]]) =:=
12+
(M[[t] =>> runtime.MatchCase[Inv[t], t]])
13+
] // error
14+
}

0 commit comments

Comments
 (0)