-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Impossible cast from Long when Java varargs are involved #13645
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
smarter
added a commit
to dotty-staging/dotty
that referenced
this issue
Oct 8, 2021
Previously, ElimRepeated correctly handled Java varargs of the form `Object...` and `T...` where `T` is a method parameter, in both cases we erased them to `Array[? <: Object]` in the denotation transformer and handled any adaptation in the tree transformer of ElimRepeated. Unfortunately, the denotation transformer logic failed to account for class type parameters, and fixing it introduced issues in override checking (RefChecks happens after ElimRepeated). So this commit gives up and delay the adaptation of primitive arrays into reference arrays until Erasure. This is less efficient in some situations but is closer to what Scala 2 does so hopefully means we won't run into more pitfalls. Fixes scala#13645.
smarter
added a commit
to dotty-staging/dotty
that referenced
this issue
Oct 8, 2021
Previously, ElimRepeated correctly handled Java varargs of the form `Object...` and `T...` where `T` is a method parameter, in both cases we erased them to `Array[? <: Object]` in the denotation transformer and handled any adaptation in the tree transformer of ElimRepeated. Unfortunately, the denotation transformer logic failed to account for class type parameters, and fixing it introduced issues in override checking (RefChecks happens after ElimRepeated). So this commit gives up and delay the adaptation of primitive arrays into reference arrays until Erasure. This is less efficient in some situations but is closer to what Scala 2 does so hopefully means we won't run into more pitfalls. Fixes scala#13645.
smarter
added a commit
to dotty-staging/dotty
that referenced
this issue
Oct 8, 2021
Previously, ElimRepeated correctly handled Java varargs of the form `Object...` and `T...` where `T` is a method parameter, in both cases we erased them to `Array[? <: Object]` in the denotation transformer and handled any adaptation in the tree transformer of ElimRepeated. Unfortunately, the denotation transformer logic failed to account for class type parameters, and fixing it introduced issues in override checking (RefChecks happens after ElimRepeated). So this commit gives up and delay the adaptation of primitive arrays into reference arrays until Erasure. This is less efficient in some situations but is closer to what Scala 2 does so hopefully means we won't run into more pitfalls. Fixes scala#13645.
smarter
added a commit
to dotty-staging/dotty
that referenced
this issue
Oct 8, 2021
Previously, ElimRepeated correctly handled Java varargs of the form `Object...` and `T...` where `T` is a method parameter, in both cases we erased them to `Array[? <: Object]` in the denotation transformer and handled any adaptation in the tree transformer of ElimRepeated. Unfortunately, the denotation transformer logic failed to account for class type parameters, and fixing it introduced issues in override checking (RefChecks happens after ElimRepeated). So this commit gives up and delay the adaptation of primitive arrays into reference arrays until Erasure. This is less efficient in some situations but is closer to what Scala 2 does so hopefully means we won't run into more pitfalls. Fixes scala#13645.
olsdavis
pushed a commit
to olsdavis/dotty
that referenced
this issue
Apr 4, 2022
Previously, ElimRepeated correctly handled Java varargs of the form `Object...` and `T...` where `T` is a method parameter, in both cases we erased them to `Array[? <: Object]` in the denotation transformer and handled any adaptation in the tree transformer of ElimRepeated. Unfortunately, the denotation transformer logic failed to account for class type parameters, and fixing it introduced issues in override checking (RefChecks happens after ElimRepeated). So this commit gives up and delay the adaptation of primitive arrays into reference arrays until Erasure. This is less efficient in some situations but is closer to what Scala 2 does so hopefully means we won't run into more pitfalls. Fixes scala#13645.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When interacting with some java code involving parametrized methods and varargs of the same type and a Scala
Long
is used, aClassCastException
is thrown at runtime as primitive long can't be casted toObject
.Compiler version
Scala
3.0.2
and3.1.0-RC2
Minimized code
You can find a repo with the code here
Given this Java class
And this Scala class:
Output
When running ImpossibleCast we get the following exception:
Expectation
The code should work (it does under Scala 2.13.6) and print:
Workaround
Notice that if we instantiate the
TypedVarargs
class withjava.lang.Long
instead of Scala'sLong
the code works as expected.The text was updated successfully, but these errors were encountered: