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 wildcard GADT constraints more directly #14832

Merged
merged 2 commits into from
Apr 9, 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: 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