Skip to content

Commit d2c9eae

Browse files
committed
Extract GADT constraints from wildcard type arguments
1 parent aea38cf commit d2c9eae

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,7 @@ trait PatternTypeConstrainer { self: TypeComparer =>
256256
val variance = param.paramVarianceSign
257257
if variance != 0 && !assumeInvariantRefinement then true
258258
else if argS.isInstanceOf[TypeBounds] || argP.isInstanceOf[TypeBounds] then
259-
// Passing TypeBounds to isSubType on LHS or RHS does the
260-
// incorrect thing and infers unsound constraints, while simply
261-
// returning true is sound. However, I believe that it should
262-
// still be possible to extract useful constraints here.
263-
// TODO extract GADT information out of wildcard type arguments
264-
true
259+
isSubType(SkolemType(patternTp), scrutineeTp)
265260
else {
266261
var res = true
267262
if variance < 1 then res &&= isSubType(argS, argP)

tests/pos/i13998.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
case class Box[V](value: V)
2+
object Box:
3+
def apply[A](a: A): Box[A] = new Box[A](a)
4+
def unapply[U](b: Box[U]): Box[U] = b
5+
6+
class Test:
7+
def value: Box[_ <: String] = Box("text")
8+
9+
def test: String = value match
10+
case Box(text) => text: String

0 commit comments

Comments
 (0)