Skip to content

Commit 98d860d

Browse files
committed
avoid leaking internal types in GadtConstraint.approximation
1 parent 28faa0f commit 98d860d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,15 @@ final class ProperGadtConstraint private(
209209
def isNarrowing: Boolean = wasConstrained
210210

211211
override def approximation(sym: Symbol, fromBelow: Boolean)(using Context): Type = {
212-
val res = approximation(tvarOrError(sym).origin, fromBelow = fromBelow)
212+
val res =
213+
approximation(tvarOrError(sym).origin, fromBelow = fromBelow) match
214+
case tpr: TypeParamRef =>
215+
// Here we do externalization when the returned type is a TypeParamRef,
216+
// b/c ConstraintHandling.approximation may return internal types when
217+
// the type variable is instantiated. See #15531.
218+
externalize(tpr)
219+
case tp => tp
220+
213221
gadts.println(i"approximating $sym ~> $res")
214222
res
215223
}

tests/pos/i15531.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
trait Tag { val data: Int }
2+
3+
enum EQ[A, B]:
4+
case Refl[C]() extends EQ[C, C]
5+
6+
def foo[T, B <: Tag](ev: EQ[T, B], x: T) = ev match
7+
case EQ.Refl() =>
8+
val i: Int = x.data
9+

0 commit comments

Comments
 (0)