-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Refine parameter adaptation logic for arrays #23591
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
base: main
Are you sure you want to change the base?
Conversation
This seems misguided to me. Why Changes to erasure are extremely risky, because they basically break tasty and binary compatibility every time. They need a very strong justification. Typically, only fixing unsoundness is a good enough reason to do this. |
Edit: Hmm it does not, at least judging by
|
If we do not want to mess with erasure, could we just uniformly use the erased SAM methodtype for the implementation method type as well in the emitted bytecode? Would this always be safe for a type-correct source program? |
Probably, but we would need to do that at the backend level. Basically consider it a bridge method, or an |
Fixes scala#23179 Since JDK 9, argument checks for LambdaMetaFactory have become stricter. Which is to say that its JDK 8 version was too lax. We apply adaptation now in case the samType is an array, but the implType is not.
Array[? >: AnyRef]
erases to Object[]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new approach seems reasonable.
It might need similar changes in ExpandSAMs
for Scala SAM types that don't translate to target SAM types.
!sameClass(implType, samType) && !autoAdaptedParam(implType) | ||
|| (samType, implType).match { | ||
case (defn.ArrayOf(_), defn.ArrayOf(_)) => false | ||
case (defn.ArrayOf(_), _) => true // see #23179 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't there be the reverse order as well ((_, defn.ArrayOf(_))
)? Like if the SAM takes an Array[T]
where T <: AnyRef
but the lambda is specialized to T = String
, for example?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm unable to construct such a reversed example that will be accepted by the compiler.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need something similar for the result type (resultAdaptationNeeded
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure, I also fail here to construct an example that would cause a run time crash (which is of course weak evidence).
I tried constructing each of the five cases in the comment at the top of |
It might be worth including the other combinations in the test case as regression tests. |
Fixes #23179
Since JDK 9, argument checks for LambdaMetaFactory have become stricter. Which is to say that its JDK 8 version was too lax.
We apply adaptation now in case the samType is an array, but the implType is not.