-
Notifications
You must be signed in to change notification settings - Fork 1.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
Illegal arguments for bootstrap method for invokedynamic #15736
Comments
Box native instantiated method return type if sam method return type is not a primitive type to satisfy conditions specified in https://docs.oracle.com/javase/8/docs/api/java/lang/invoke/LambdaMetafactory.html Condition is not enforced by JVM but by Android ART.
The Corresponding code in the compiler: https://github.com/scala/scala/blob/v2.13.16/src/compiler/scala/tools/nsc/transform/Delambdafy.scala#L162-L175 ASM of the Scala 2 compiled class:
|
Oh, I only saw the PR now. Will take a look, probably next week though.. |
Compiler version
3.1.3
Description
When compiling a lambda, the arguments to the generated bootstrap method in the generated class file violate the rules given in the JDK documentation. While this does not seem to cause any issues on OpenJDK, the Android Dexer d8 cannot handle this.
According to https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/lang/invoke/LambdaMetafactory.html interfaceMethodType and dynamicMethodType have to fullfill the following constraints:
There is no type conversion between primitive types and reference types
In the following example, the scala compiler generates a bootstrap method call to LambdaMetafactory.altMetafactory with
interfaceMethodType: (Ljava/lang/Object;)Ljava/lang/Object;
dynamicMethodType: (Ljava/lang/Object;)Z
This clearly violates the specifiaction of LambdaMetafactory.
The dynamicMethodeType should be (Ljava/lang/Object;)Ljava/lang/Boolean;
It is ok for the MethodHandle supplied as implementation to have a MethodType of (Ljava/lang/Object;)Z, LambdaMetafactory will handle boxing, but the dynamicMethodType has to specify the boxed types.
Minimized code
Output
Taken from javap -private -c -v
Expectation
Taken from javap -private -c -v
The text was updated successfully, but these errors were encountered: