-
Notifications
You must be signed in to change notification settings - Fork 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
Dotty does not erase intersection types like scalac #4619
Comments
Does this also affect erasure in calls to Scala2-defined methods? That would make the issue even more important. |
Yes, I think so. |
Related ticket: #2920 |
smarter
added a commit
to dotty-staging/dotty
that referenced
this issue
Mar 4, 2021
Because our algorithm for erasing intersection types does not exactly match the one used by Scala 2, we could end up emitting calls to Scala 2 methods with the wrong bytecode signature, leading to NoSuchMethodError at runtime. We could try to exactly match what Scala 2 does, but it turns out that the Scala 2 logic heavily relies on implementation details which makes it extremely complex to reliably replicate. Therefore, this commit instead special-cases the erasure of Scala 2 intersections (just like we already special-case the erasure of Java intersections) and limits which Scala 2 intersection types we support to a subset that we can erase without too much complications (but even that still requires ~200 lines of code!). This means that we're now free to change the way we erase intersections in any way we want without introducing more compatibility problems (until 3.0.0 that is), I'll explore this in a follow-up PR. Fixes scala#4619. Fixes scala#9175.
smarter
added a commit
to dotty-staging/dotty
that referenced
this issue
Mar 4, 2021
Because our algorithm for erasing intersection types does not exactly match the one used by Scala 2, we could end up emitting calls to Scala 2 methods with the wrong bytecode signature, leading to NoSuchMethodError at runtime. We could try to exactly match what Scala 2 does, but it turns out that the Scala 2 logic heavily relies on implementation details which makes it extremely complex to reliably replicate. Therefore, this commit instead special-cases the erasure of Scala 2 intersections (just like we already special-case the erasure of Java intersections) and limits which Scala 2 intersection types we support to a subset that we can erase without too much complications (but even that still requires ~200 lines of code!). This means that we're now free to change the way we erase intersections in any way we want without introducing more compatibility problems (until 3.0.0 that is), I'll explore this in a follow-up PR. Fixes scala#4619. Fixes scala#9175.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Given:
Scala 2 erases it as:
But Dotty erases it as:
This is problematic since it can affect which overloads are valid or not.
The Scala 2 implementation is at https://github.com/scala/scala/blob/a9275b50e425d29c0b7fd45c10317953d5bf7804/src/reflect/scala/reflect/internal/transform/Erasure.scala#L333-L366
The Dotty implementation is at https://github.com/lampepfl/dotty/blob/868d1995b0f10bacf13d365e12eb2b31061a1928/compiler/src/dotty/tools/dotc/core/TypeErasure.scala#L290-L315
The text was updated successfully, but these errors were encountered: