Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid leaking internal types in GadtConstraint.approximation #15558

Merged
merged 1 commit into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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