Created
January 29, 2015 04:04
-
-
Save SeanTAllen/233453e9f545db4529fe to your computer and use it in GitHub Desktop.
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
// WHY DOES PATTERN MATCH EXHAUSTIVENESS CHECK ONLY WORK WHEN | |
// THE CASE CLASS IS SEALED? | |
case class Foo(a: Option[String]) | |
sealed case class Bar(a: Option[String]) | |
sealed trait Zed | |
case class Alpha(a: Option[String]) extends Zed | |
// This causes a scala matchError at runtime | |
Foo(None) match { | |
case Foo(Some(x)) => x | |
} | |
// This causes compile time exhaustive-ness warning | |
Bar(None) match { | |
case Bar(Some(x)) => x | |
} | |
// This causes a scala matchError at runtime | |
Alpha(None) match { | |
case Alpha(Some(x)) => x | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment