From 7ed8da5304fbb8a831169f89768659a87cfcd563 Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Sun, 3 Apr 2022 15:37:40 +0100 Subject: [PATCH 1/2] Extract wildcard GADT constraints more directly --- .../tools/dotc/core/PatternTypeConstrainer.scala | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/core/PatternTypeConstrainer.scala b/compiler/src/dotty/tools/dotc/core/PatternTypeConstrainer.scala index 9aa27919b52d..ac7cbf6c36a6 100644 --- a/compiler/src/dotty/tools/dotc/core/PatternTypeConstrainer.scala +++ b/compiler/src/dotty/tools/dotc/core/PatternTypeConstrainer.scala @@ -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 } } From 9bc8c9b9aa8104fd8cb91fa9bd84bfaaf322402c Mon Sep 17 00:00:00 2001 From: Dale Wijnand Date: Thu, 7 Apr 2022 14:20:21 +0100 Subject: [PATCH 2/2] Add a test case there the pattern has a bound Looking at the log of constr, gadts, and gadtsConstr there seems to be no change in behaviour compared to before the implementation change in PatternTypeConstrainer. --- tests/pos/i14832.scala | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 tests/pos/i14832.scala diff --git a/tests/pos/i14832.scala b/tests/pos/i14832.scala new file mode 100644 index 000000000000..9f486062e111 --- /dev/null +++ b/tests/pos/i14832.scala @@ -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