Skip to content

Commit fddd576

Browse files
author
Adriaan Moors
committed
don't check exhaustivity involving user-defined unapplySeq
1 parent bcc8280 commit fddd576

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

src/compiler/scala/tools/nsc/typechecker/PatternMatching.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1973,6 +1973,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
19731973
case Some(0) if testedBinder.tpe.typeSymbol == ListClass => // extractor.symbol.owner == SeqFactory
19741974
EqualityCond(binderToUniqueTree(p.prevBinder), unique(Ident(NilModule) setType NilModule.tpe))
19751975
case _ =>
1976+
backoff = true
19761977
super.treeMakerToCond(tm)
19771978
}
19781979
case ExtractorTreeMaker(_, _, _, _) =>

test/files/neg/patmatexhaust.check

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,6 @@ patmatexhaust.scala:53: error: match may not be exhaustive.
1818
It would fail on the following input: Gp()
1919
def ma5(x:Deep) = x match {
2020
^
21-
patmatexhaust.scala:59: error: match may not be exhaustive.
22-
It would fail on the following input: Nil
23-
def ma6() = List(1,2) match { // give up
24-
^
2521
patmatexhaust.scala:75: error: match may not be exhaustive.
2622
It would fail on the following input: B()
2723
def ma9(x: B) = x match {
@@ -38,4 +34,4 @@ patmatexhaust.scala:126: error: match may not be exhaustive.
3834
It would fail on the following input: C1()
3935
def ma10(x: C) = x match { // not exhaustive: C1 is not abstract.
4036
^
41-
10 errors found
37+
9 errors found

test/files/pos/exhaustive_heuristics.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,15 @@ object Test {
1212
case _ if turnOffChecks =>
1313
}
1414

15-
// TODO: we back off when there are any user-defined extractors
15+
// we back off when there are any user-defined extractors
16+
// in fact this is exhaustive, but we pretend we don't know since List's unapplySeq is not special to the compiler
17+
// to compensate our ignorance, we back off
18+
// well, in truth, we do rewrite List() to Nil, but otherwise we do nothing
19+
// the full rewrite List(a, b) to a :: b :: Nil, for example is planned (but not sure it's a good idea)
20+
List(true, false) match {
21+
case List(_, _, _*) =>
22+
case List(node, _*) =>
23+
case Nil =>
24+
}
25+
1626
}

0 commit comments

Comments
 (0)