-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
improve Unreachable case
error message
#18519
Comments
@dwijnand I think the compiler is right, can you check it too, thanks. |
I also checked this independently when I was testing pekko with pipeline compilation support, in the source file However for the project maintainers perhaps they should swap the cases. |
I've tested it when investigating nightly failures in Open Community Build for akka/pekko and it's an improvement and not a regression. As @bishabosha already mentioned all the cases for |
That's true. |
Thank you everyone. |
@bishabosha Is it possible to improve the error message, I mean you can reopen this issue with a different tile, or start a new issue. |
Unreachable case
after update to 3.3.1Unreachable case
error message
to summarise, the error message for "unreachable case" could be expanded to mention which cases already cover the "unreachable" case mentioned. This could help the programmer re-order the code if they really need to do something different when that case matches, e.g. in the Pekko code mentioned, there is meant to be special behaviour specifically for the |
minimisation: sealed trait ServerOp
sealed trait NetworkOp
case object Done extends ServerOp with NetworkOp
case class Foo() extends ServerOp with NetworkOp
def foo(x: Matchable) = x match
case Done => ???
case _: NetworkOp => ???
case _: ServerOp => ??? // warning: Unreachable case |
How? By trying all the combinations of all the cases to find the smallest set of cases that make the case redundant? Currently we don't compare the case to individual previous cases, we just take all previous cases and consider whether the current case is redundant. I don't think we should spend the CPU time doing more, unless it's an opt-in option. |
This is just a thought without much knowledge of the implementation, but could you keep a reference to the original tree that the space element comes from, then whenever some part covers the case then you can recover which cases were responsible? |
The calculation is |
There's also the issue of inlining. For inlined code we don't even see the pattern and the match, so "unreachable case" is particularly unhelpful. |
Compiler version
3.3.1
Minimized code
Not minimized yet.
multi-node-testkit
with scala 3.3.1Output
Expectation
I just check the code, the branches will be matched with
first , so I think the compiler is right.
Better with an output:
The text was updated successfully, but these errors were encountered: