Skip to content

Commit ebe3d54

Browse files
authored
Merge pull request #14832 from dwijnand/extract-wildcard-gadt-constraints
Extract wildcard GADT constraints more directly
2 parents 298762a + 9bc8c9b commit ebe3d54

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

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

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -255,18 +255,11 @@ trait PatternTypeConstrainer { self: TypeComparer =>
255255
tyconS.typeParams.lazyZip(argsS).lazyZip(argsP).forall { (param, argS, argP) =>
256256
val variance = param.paramVarianceSign
257257
if variance != 0 && !assumeInvariantRefinement then true
258-
else if argS.isInstanceOf[TypeBounds] || argP.isInstanceOf[TypeBounds] then
259-
// This line was added here as a quick fix for issue #13998,
260-
// to extract GADT constraints from wildcard type arguments.
261-
// The proper fix would involve inspecting the bounds right here and performing the
262-
// correct subtyping checks, the ones that are already performed by `isSubType` below,
263-
// for the same reasons for which we stopped using `SkolemType` here to begin with
264-
// (commit 10fe5374dc2d).
265-
isSubType(SkolemType(patternTp), scrutineeTp)
266258
else {
259+
val TypeBounds(loS, hiS) = argS.bounds
267260
var res = true
268-
if variance < 1 then res &&= isSubType(argS, argP)
269-
if variance > -1 then res &&= isSubType(argP, argS)
261+
if variance < 1 then res &&= isSubType(loS, argP)
262+
if variance > -1 then res &&= isSubType(argP, hiS)
270263
res
271264
}
272265
}

tests/pos/i14832.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class Box[V](val value: V)
2+
3+
class Test:
4+
def value: Box["text"] = Box("text")
5+
6+
def test: String = value match
7+
case b: Box[_ <: String] => b.value

0 commit comments

Comments
 (0)