Created
November 30, 2018 14:56
-
-
Save mpilquist/2fa3244bf6a73d5cbc765517896cf754 to your computer and use it in GitHub Desktop.
Exhaustiveness failure with type aliases
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
➜ scala-2.13.0-M5 ./bin/scala [I] | |
Welcome to Scala 2.13.0-M5 (OpenJDK 64-Bit Server VM, Java 11.0.1). | |
Type in expressions for evaluation. Or try :help. | |
scala> :paste | |
// Entering paste mode (ctrl-D to finish) | |
sealed trait Color | |
case object Red extends Color | |
case object Blue extends Color | |
case object Green extends Color | |
type RGB = Color | |
val R: RGB = Red | |
val B: RGB = Blue | |
val G: RGB = Green | |
def go(c: RGB): Int = c match { | |
case R => 0 | |
case G => 1 | |
case B => 2 | |
} | |
// Exiting paste mode, now interpreting. | |
def go(c: RGB): Int = c match { | |
^ | |
On line 11: warning: match may not be exhaustive. | |
It would fail on the following inputs: Blue, Green, Red | |
defined trait Color | |
defined object Red | |
defined object Blue | |
defined object Green | |
defined type alias RGB | |
R: RGB = Red | |
B: RGB = Blue | |
G: RGB = Green | |
go: (c: RGB)Int |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment