Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always check exhaustivity of custom extractors/guards
- Loading branch information
Showing
13 changed files
with
78 additions
and
42 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
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 |
---|---|---|
@@ -1,15 +1,31 @@ | ||
t5365.scala:2: warning: match may not be exhaustive. | ||
It would fail on the following input: None | ||
t5365.scala:3: warning: match may not be exhaustive. | ||
It would fail on the following inputs: None, Some(_) | ||
def nonExhautiveIfWeAssumeGuardsTrueOrFalse(x: Option[Int]): Int = x match { | ||
^ | ||
t5365.scala:17: warning: match may not be exhaustive. | ||
It would fail on the following input: None | ||
t5365.scala:7: warning: match may not be exhaustive. | ||
It would fail on the following input: Some(_) | ||
def nonExhautiveIfWeAssumeGuardsFalse(x: Option[Int]): Int = x match { | ||
^ | ||
t5365.scala:12: warning: match may not be exhaustive. | ||
It would fail on the following input: Some(_) | ||
def inverseGuards(x: Option[Int]): Int = x match { | ||
^ | ||
t5365.scala:18: warning: match may not be exhaustive. | ||
It would fail on the following inputs: None, Some(_) | ||
def extractor(x: Option[Int]) = x match { | ||
^ | ||
t5365.scala:20: warning: match may not be exhaustive. | ||
It would fail on the following input: None | ||
t5365.scala:21: warning: match may not be exhaustive. | ||
It would fail on the following inputs: None, Some(_) | ||
def repeatedExtractor(x: Option[Int]) = x match { | ||
^ | ||
t5365.scala:24: warning: match may not be exhaustive. | ||
It would fail on the following input: Some(_) | ||
def extractorStrict(x: Option[Int]) = x match { | ||
^ | ||
t5365.scala:28: warning: match may not be exhaustive. | ||
It would fail on the following input: Some(_) | ||
def repeatedExtractorStrict(x: Option[Int]) = x match { | ||
^ | ||
error: No warnings can be incurred under -Xfatal-warnings. | ||
three warnings found | ||
7 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
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
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
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 |
---|---|---|
@@ -1,23 +1,27 @@ | ||
t5365e.scala:7: warning: match may not be exhaustive. | ||
It would fail on the following input: Bar(_) | ||
t5365e.scala:8: warning: match may not be exhaustive. | ||
It would fail on the following inputs: Bar(_), Foo(_) | ||
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(_) | ||
t5365e.scala:9: warning: match may not be exhaustive. | ||
It would fail on the following inputs: Bar(_), Foo(_) | ||
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(_) | ||
t5365e.scala:10: warning: match may not be exhaustive. | ||
It would fail on the following inputs: Bar(_), Foo(_) | ||
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. | ||
t5365e.scala:11: 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. | ||
t5365e.scala:12: 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 | ||
^ | ||
t5365e.scala:13: 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 } // pessimistically inexhaustive | ||
^ | ||
error: No warnings can be incurred under -Xfatal-warnings. | ||
5 warnings found | ||
6 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
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