Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
These two casts are necessary to compile cats-core with Dotty. I've been using them locally in my cross-compilation experiments, but wanted to understand for myself why Dotty wants them before opening a PR.
I've just been taking a closer look and have convinced myself that in both cases Dotty is doing the right thing, and Scala 2 only compiles the current code because of soundness bugs.
In
AndThen
, the issue is that the compiler is inferring theE
to beAny
in theConcat
case, which isn't sound in general. Consider the following simplification:Inferring
Nothing
here is the safe thing to do, and this failure makes sense. You can trick the compiler into inferring theA
to beAny
, though, simply by having it appear in a non-contravariant position in another member:…which will fail at runtime on e.g.
Foo[Int]
:Dotty fixes this and refuses to compile the second
Foo
, and it fails onAndThen
for the same reason:The
Eval
code also compiles only because the Scala 2 compiler is too willing to inferAny
. Here's a simplified example that shows the unsoundness:And then:
In context both of these cases are optimizations where we're already doing a lot of casting, and personally I think it's reasonable to add two more casts to satisfy the Dotty compiler.