-
Notifications
You must be signed in to change notification settings - Fork 21
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
Mixin generates method signatures that confuse javac #6103
Comments
Imported From: https://issues.scala-lang.org/browse/SI-6103?orig=1 |
@axel22 said: Scala: trait Func1[T1, R] {
def apply(v1: T1): R = null.asInstanceOf[R]
}
class Func1ReturnString[T] extends Func1[T, String] Java: public class Test {
public static void main(String[] args) {
Func1ReturnString<Integer> b = new Func1ReturnString<Integer>() {};
b.apply(0);
}
} At runtime: Exception in thread "main" java.lang.NoSuchMethodError: Func1ReturnString.apply(Ljava/lang/Object;)Ljava/lang/String;
at Test.main(Test.java:7) |
@paulp said: |
@gkossakowski said: |
@paulp said: |
@paulp said:
That demonstrates the essence of the problem: concrete types cannot be directly substituted for corresponding type parameters in the signatures of mixed in methods, because the underlying concrete implementation will have the erasure of the type parameters, not of the concrete types. In other words, "Func1" knows nothing of "String", but "Func1ReturnString" thinks it can substitute String for T and everything will work out. It won't. It's elaborated on at some length in the commit. |
@VladUreche said: |
@paulp said: |
@lrytz said: The conclusion of the meeting discussion was that this bug popped up with scalac generating more / better java generic signatures. What scalac does on the bytecode level is correct, and also the signatures are correct, the problem is rather in javac which is not able to work correctly with these classfiles. |
@paulp said: |
@VladUreche said: |
@retronym said: |
@VladUreche said (edited on Jul 25, 2012 8:04:16 AM UTC): I've had a look at the bugs that concern AnyRef specialization and it's not such a long list: #6103, #6043, #4790, #5976 and #5583. If we make a big push to fix all of them by the next milestone, maybe we can re-enable the AnyRef specialization. |
@gkossakowski said: Now, Martin said that the issue with mixin cannot be fixed (because it runs after erasure) so we have two options:
We decided to go with the second option. I think it's too late in 2.10 cycle to do anything more ambitious. We can try to do better than that for 2.11 (2.10.1 is out of question due to binary compatibility concerns). |
@retronym said: |
@paulp said:
"Mixin generates broken code and can't be fixed no matter what" is not a sensible premise from which to analyze this issue. |
@VladUreche said: |
Strictly speaking, this is not a regression, but causes other regressions in the standard library (see #6101, #5976), and may be a blocker.
Scala file:
Java file:
This crashes
javac
:The reason is that
mixin
does not generate an appropriate signature forapply
. Trees at the end ofcleanup
:If you look at
apply
above, the return type isObject
instead ofString
. This happens in general whenever a method signature changes due to a more refined type environment in an inheriting class and the method is not overridden/implemented in the inheriting class.In some other situations
javac
compiles the file, but produces bytecode which refers to a non-existing method (signature-wise). See an example in a comment below.This happens both with Scala 2.9.2 and Scala 2.10.x.
It does not happen with Scala 2.8.2, but we think this is because in Scala 2.8.2 the generic signatures were broken in other ways. Furthermore, it also breaks with 2.8.2 if you change the Java code a bit:
The text was updated successfully, but these errors were encountered: