Skip to content
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

Handle Java varargs T... where T is a class parameter #13718

Merged
merged 1 commit into from Oct 8, 2021

Conversation

smarter
Copy link
Member

@smarter smarter commented 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 #13645.

@smarter smarter force-pushed the java-varargs-erasure-3 branch 2 times, most recently from 9ccc78a to 324e3ec Compare October 8, 2021 12:28
@smarter smarter requested a review from odersky October 8, 2021 13:46
@@ -145,7 +130,7 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
val tpe = arg.expr.tpe
if isJavaDefined then
val pt = tree.fun.tpe.widen.firstParamTypes.last
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This definition is not used

Suggested change
val pt = tree.fun.tpe.widen.firstParamTypes.last

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 smarter enabled auto-merge October 8, 2021 19:24
@smarter smarter merged commit 0a89c6f into scala:master Oct 8, 2021
@smarter smarter deleted the java-varargs-erasure-3 branch October 8, 2021 20:27
@Kordyjan Kordyjan added this to the 3.1.1 milestone Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Impossible cast from Long when Java varargs are involved
3 participants