Skip to content

Commit

Permalink
Merge pull request #14832 from dwijnand/extract-wildcard-gadt-constra…
Browse files Browse the repository at this point in the history
…ints

Extract wildcard GADT constraints more directly
  • Loading branch information
abgruszecki authored Apr 9, 2022
2 parents 298762a + 9bc8c9b commit ebe3d54
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
13 changes: 3 additions & 10 deletions compiler/src/dotty/tools/dotc/core/PatternTypeConstrainer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -255,18 +255,11 @@ trait PatternTypeConstrainer { self: TypeComparer =>
tyconS.typeParams.lazyZip(argsS).lazyZip(argsP).forall { (param, argS, argP) =>
val variance = param.paramVarianceSign
if variance != 0 && !assumeInvariantRefinement then true
else if argS.isInstanceOf[TypeBounds] || argP.isInstanceOf[TypeBounds] then
// 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)
else {
val TypeBounds(loS, hiS) = argS.bounds
var res = true
if variance < 1 then res &&= isSubType(argS, argP)
if variance > -1 then res &&= isSubType(argP, argS)
if variance < 1 then res &&= isSubType(loS, argP)
if variance > -1 then res &&= isSubType(argP, hiS)
res
}
}
Expand Down
7 changes: 7 additions & 0 deletions tests/pos/i14832.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Box[V](val value: V)

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

def test: String = value match
case b: Box[_ <: String] => b.value

0 comments on commit ebe3d54

Please sign in to comment.