Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9474 from dwijnand/patmat-unapply-uninhabited-sealed
Emit exhaustivity warning despite uninhabited types
- Loading branch information
Showing
3 changed files
with
56 additions
and
2 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,11 @@ | ||
t8511.scala:28: warning: unreachable code | ||
??? | ||
^ | ||
t8511.scala:23: warning: match may not be exhaustive. | ||
It would fail on the following inputs: Bar(_), Baz(), EatsExhaustiveWarning(_) | ||
private def logic(head: Expr): String = head match { | ||
^ | ||
warning: 1 deprecation (since 2.13.0); re-run with -deprecation for details | ||
error: No warnings can be incurred under -Werror. | ||
3 warnings | ||
1 error |
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,30 @@ | ||
// scalac: -Werror | ||
sealed trait Expr | ||
final case class Foo(other: Option[String]) extends Expr | ||
final case class Bar(someConstant: String) extends Expr | ||
final case class Baz() extends Expr | ||
final case class EatsExhaustiveWarning(other: Reference) extends Expr | ||
|
||
sealed trait Reference { | ||
val value: String | ||
} | ||
|
||
object Reference { | ||
def unapply(reference: Reference): Option[(String)] = { | ||
Some(reference.value) | ||
} | ||
} | ||
|
||
object EntryPoint { | ||
def main(args: Array[String]) { | ||
println("Successfully ran") | ||
} | ||
|
||
private def logic(head: Expr): String = head match { | ||
case Foo(_) => | ||
??? | ||
// Commenting this line only causes the exhaustive search warning to be emitted | ||
case EatsExhaustiveWarning(Reference(text)) => | ||
??? | ||
} | ||
} |