Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check exhaustivity of case class unapplySeq extractors too
ProductExtractorTreeMaker handles non-custom extractors, i.e. the synthetic ones generates for case classes. I think this case was just accidentally missing from the original commit. The change to run/virtpatmat_unapplyprod makes sense to me - it's an inexhaustive match, albeit with complicated counter-examples... :( This is the actually the last remaining tree maker, so none will back off after this, from my reading - but I kept the back-off stuff as is, keeping the diff minimal, to try to land this as easily as possible.
- Loading branch information
Showing
5 changed files
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
t5365e.scala:7: warning: match may not be exhaustive. | ||
It would fail on the following input: Bar(_) | ||
def f0(x: Exh) = x match { case Foo() => () } // don't back off | ||
^ | ||
t5365e.scala:8: warning: match may not be exhaustive. | ||
It would fail on the following input: Bar(_) | ||
def f1(x: Exh) = x match { case Foo(x) => x } // don't back off | ||
^ | ||
t5365e.scala:9: warning: match may not be exhaustive. | ||
It would fail on the following input: Bar(_) | ||
def f2(x: Exh) = x match { case Foo(x, y) => x + y } // don't back off | ||
^ | ||
t5365e.scala:10: warning: match may not be exhaustive. | ||
It would fail on the following input: Bar(_) | ||
def fX(x: Exh) = x match { case Foo(xs @ _*) => xs } // don't back off | ||
^ | ||
t5365e.scala:11: warning: match may not be exhaustive. | ||
It would fail on the following input: Foo(_) | ||
def b1(x: Exh) = x match { case Bar(x) => x } // inexhaustive | ||
^ | ||
error: No warnings can be incurred under -Xfatal-warnings. | ||
5 warnings found | ||
one error found |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-Xfatal-warnings |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
sealed trait Exh | ||
final case class Foo(xs: String*) extends Exh | ||
final case class Bar(x: String) extends Exh | ||
|
||
class Main { | ||
def ex(x: Exh) = x match { case Foo(xs @ _*) => xs case Bar(x) => x } // exhaustive | ||
def f0(x: Exh) = x match { case Foo() => () } // don't back off | ||
def f1(x: Exh) = x match { case Foo(x) => x } // don't back off | ||
def f2(x: Exh) = x match { case Foo(x, y) => x + y } // don't back off | ||
def fX(x: Exh) = x match { case Foo(xs @ _*) => xs } // don't back off | ||
def b1(x: Exh) = x match { case Bar(x) => x } // inexhaustive | ||
def fb(x: Exh) = x match { case Foo(x) => x case Bar(x) => x } // optimistically exhaustive | ||
// ^ under -Xstrict-patmat-analysis pessimistically approximates case Foo(x) as inexhaustive: | ||
// test/files/neg/t5365e.scala:12: warning: match may not be exhaustive. | ||
// It would fail on the following input: Foo(_) | ||
// def fb(x: Exh) = x match { case Foo(x) => x case Bar(x) => x } // optimistically exhaustive | ||
// ^ | ||
// ... and the counter-example needs work -.- ... | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters