-
Notifications
You must be signed in to change notification settings - Fork 555
Remove remaining unsafe cast from Resource interpreters #1187
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
Conversation
Incredible |
While I'm 💯 % 👍 for this change, I have a hunch that on 2.x it's only compiling by accident (ie. it would continue to compile even if the RHS of the pattern was unsound). I've run into these kinds of false dawn before, and the code here is reminiscent of some of the examples here. That said, Dotty is getting this right now, so even if scalac is giving us a false sense of security here, the fact that it cross compiles with dotc should give us confidence that we're not getting away with anything we're not genuinely entitled to. |
Dotty does warn about some stuff here so no guarantee of soundness: [warn] -- Warning: /home/runner/work/cats-effect/cats-effect/core/shared/src/main/scala/cats/effect/Resource.scala:119:13
[warn] 119 | case a: Allocate[G, C] =>
[warn] | ^^^^^^^^^^^^^^^^^
[warn] |the type test for cats.effect.Resource.Allocate[G, C] cannot be checked at runtime |
(these all come from the fact that Resource is covariant in its type parameters but its subclasses aren't) |
It no longer compiles if you try to call the |
This is the appropriate reaction 😄 |
That can be fixed in Dotty by using |
Shouldn't the subclasses also be covariant? |
Ah, and if if you do that you don't need asInstanceOf? That sounds good then
Most of them can't be due to the positions in which their parameters are used, there was some related discussion on gitter a few weeks ago. |
Correct, though interestingly Dotty then fails to find the |
Somewhat amazingly, it turns out we don't even need the final cast when outputting the result (though IntelliJ complains).