Skip to content

Commit 812f8c5

Browse files
committed
Extract GADT constraints from wildcard type arguments
1 parent 7bf25f5 commit 812f8c5

File tree

3 files changed

+16
-13
lines changed

3 files changed

+16
-13
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)

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -339,14 +339,12 @@ trait ParallelTesting extends RunnerOrchestration { self =>
339339
}
340340

341341
/** All testSources left after filtering out */
342-
private val filteredSources =
343-
if (!testFilter.isDefined) testSources
344-
else testSources.filter {
345-
case JointCompilationSource(_, files, _, _, _, _) =>
346-
files.exists(file => file.getPath.contains(testFilter.get))
347-
case SeparateCompilationSource(_, dir, _, _) =>
348-
dir.getPath.contains(testFilter.get)
342+
private val filteredSources = testFilter.map(_.split(',')) match
343+
case Some(testFilters) => testSources.filter {
344+
case JointCompilationSource(_, files, _, _, _, _) => files.exists(f => testFilters.exists(f.getPath.contains))
345+
case SeparateCompilationSource(_, dir, _, _) => testFilters.exists(dir.getPath.contains)
349346
}
347+
case _ => testSources
350348

351349
/** Total amount of test sources being compiled by this test */
352350
val sourceCount = filteredSources.length

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)