Skip to content

Commit

Permalink
don't check exhaustivity involving user-defined unapplySeq
Browse files Browse the repository at this point in the history
  • Loading branch information
adriaanm committed May 28, 2012
1 parent bcc8280 commit fddd576
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1973,6 +1973,7 @@ trait PatternMatching extends Transform with TypingTransformers with ast.TreeDSL
case Some(0) if testedBinder.tpe.typeSymbol == ListClass => // extractor.symbol.owner == SeqFactory case Some(0) if testedBinder.tpe.typeSymbol == ListClass => // extractor.symbol.owner == SeqFactory
EqualityCond(binderToUniqueTree(p.prevBinder), unique(Ident(NilModule) setType NilModule.tpe)) EqualityCond(binderToUniqueTree(p.prevBinder), unique(Ident(NilModule) setType NilModule.tpe))
case _ => case _ =>
backoff = true
super.treeMakerToCond(tm) super.treeMakerToCond(tm)
} }
case ExtractorTreeMaker(_, _, _, _) => case ExtractorTreeMaker(_, _, _, _) =>
Expand Down
6 changes: 1 addition & 5 deletions test/files/neg/patmatexhaust.check
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,10 +18,6 @@ patmatexhaust.scala:53: error: match may not be exhaustive.
It would fail on the following input: Gp() It would fail on the following input: Gp()
def ma5(x:Deep) = x match { def ma5(x:Deep) = x match {
^ ^
patmatexhaust.scala:59: error: match may not be exhaustive.
It would fail on the following input: Nil
def ma6() = List(1,2) match { // give up
^
patmatexhaust.scala:75: error: match may not be exhaustive. patmatexhaust.scala:75: error: match may not be exhaustive.
It would fail on the following input: B() It would fail on the following input: B()
def ma9(x: B) = x match { def ma9(x: B) = x match {
Expand All @@ -38,4 +34,4 @@ patmatexhaust.scala:126: error: match may not be exhaustive.
It would fail on the following input: C1() It would fail on the following input: C1()
def ma10(x: C) = x match { // not exhaustive: C1 is not abstract. def ma10(x: C) = x match { // not exhaustive: C1 is not abstract.
^ ^
10 errors found 9 errors found
12 changes: 11 additions & 1 deletion test/files/pos/exhaustive_heuristics.scala
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,5 +12,15 @@ object Test {
case _ if turnOffChecks => case _ if turnOffChecks =>
} }


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

} }

0 comments on commit fddd576

Please sign in to comment.