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

Extract GADT constraints from wildcard type arguments #14132

Merged
merged 1 commit into from
Jan 24, 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
13 changes: 7 additions & 6 deletions compiler/src/dotty/tools/dotc/core/PatternTypeConstrainer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -256,12 +256,13 @@ trait PatternTypeConstrainer { self: TypeComparer =>
val variance = param.paramVarianceSign
if variance != 0 && !assumeInvariantRefinement then true
else if argS.isInstanceOf[TypeBounds] || argP.isInstanceOf[TypeBounds] then
// Passing TypeBounds to isSubType on LHS or RHS does the
// incorrect thing and infers unsound constraints, while simply
// returning true is sound. However, I believe that it should
// still be possible to extract useful constraints here.
// TODO extract GADT information out of wildcard type arguments
true
// This line was added here as a quick fix for issue #13998,
// to extract GADT constraints from wildcard type arguments.
// The proper fix would involve inspecting the bounds right here and performing the
// correct subtyping checks, the ones that are already performed by `isSubType` below,
// for the same reasons for which we stopped using `SkolemType` here to begin with
// (commit 10fe5374dc2d).
isSubType(SkolemType(patternTp), scrutineeTp)
abgruszecki marked this conversation as resolved.
Show resolved Hide resolved
else {
var res = true
if variance < 1 then res &&= isSubType(argS, argP)
Expand Down
10 changes: 10 additions & 0 deletions tests/pos/i13998.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
case class Box[V](value: V)
object Box:
def apply[A](a: A): Box[A] = new Box[A](a)
def unapply[U](b: Box[U]): Box[U] = b

class Test:
def value: Box[_ <: String] = Box("text")

def test: String = value match
case Box(text) => text: String