-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Spurious "Unreachable case" warning in a match on an ADT #14807
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Minimized to: case class Two(month: java.time.Month)
def doSomething(foo: Any) = foo match
case Two(x) =>
case _ => Intermediate cause: The pattern matcher tries to see if the space of all values covered by In this case, on the line above, the decomposition algorithm thinks that the The question is why is it empty? |
The children in the original enum case are not empty, though. I see: |
I could not reproduce that either. For me, the warning appears no matter what the case ordering is. |
Yeah, I changed the way warnings are emitted so those reorderings don't affect the behaviour, but I'm guessing that fix isn't released or wasn't the version Chris was running. I'll look into why Month has no children, which I agree with @anatoliykmetyuk seems like is the root cause. On the side, I think the behaviour of considering the case unreachable if it contains an uninhabited type seems reasonable to me: like a sealed trait with no children should cause the outer case to be unreachable. |
|
This means the following code is wrong by definition: It will always have empty children. |
Ah, I guess Java enums should have children. Not sure whether that's the case in general. |
Compiler version
3.1.1
Minimized code
Output
Expectation
Compiles without warnings, like Scala 2.13.
Notes
Surprisingly, if I switch the lines around to make
case Foo.Two(x, y)
the very first case in the match, the warning goes away.The text was updated successfully, but these errors were encountered: