Skip to content

Commit

Permalink
avoid leaking internal types in GadtConstraint.approximation
Browse files Browse the repository at this point in the history
  • Loading branch information
Linyxus committed Jun 30, 2022
1 parent b0671c0 commit 5a6f7e7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compiler/src/dotty/tools/dotc/core/GadtConstraint.scala
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,15 @@ final class ProperGadtConstraint private(
def isNarrowing: Boolean = wasConstrained

override def approximation(sym: Symbol, fromBelow: Boolean)(using Context): Type = {
val res = approximation(tvarOrError(sym).origin, fromBelow = fromBelow)
val res =
approximation(tvarOrError(sym).origin, fromBelow = fromBelow) match
case tpr: TypeParamRef =>
// Here we do externalization when the returned type is a TypeParamRef,
// b/c ConstraintHandling.approximation may return internal types when
// the type variable is instantiated. See #15531.
externalize(tpr)
case tp => tp

gadts.println(i"approximating $sym ~> $res")
res
}
Expand Down
9 changes: 9 additions & 0 deletions tests/pos/i15531.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
trait Tag { val data: Int }

enum EQ[A, B]:
case Refl[C]() extends EQ[C, C]

def foo[T, B <: Tag](ev: EQ[T, B], x: T) = ev match
case EQ.Refl() =>
val i: Int = x.data

0 comments on commit 5a6f7e7

Please sign in to comment.