Skip to content

Instantly share code, notes, and snippets.

@SeanTAllen
Created January 29, 2015 04:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SeanTAllen/233453e9f545db4529fe to your computer and use it in GitHub Desktop.
Save SeanTAllen/233453e9f545db4529fe to your computer and use it in GitHub Desktop.
// 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