-
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
AnyRef specialization broken when traits, abstract classes and classes are involved #6043
Comments
Imported From: https://issues.scala-lang.org/browse/SI-6043?orig=1 |
@paulp said: Are you sure of this assessment? This looks more to me like a case of comparing types in the wrong environment. In Baz, A=String, and def apply(x: String): Boolean exists. When looking for specialized overrides involving A, (String)Boolean is exactly the method signature it ought to be looking for. The fact that it doesn't override it says to me it's looking for the wrong signature, not that it needs to apply a different test. Parameter types of method overrides must match exactly, which also makes me skeptical that a subtype test is what's needed. |
@adriaanm said: |
@axel22 said: but I still have to test it, and right now I have my hands full with @static. |
@non said (edited on Aug 14, 2012 4:37:49 AM UTC): If you change Inter into a trait, you'll see specialization occuring: public class Baz extends java.lang.Object implements Inter{
public boolean apply$mcI$sp(int);
public boolean apply(java.lang.String);
public boolean apply(java.lang.Object);
public Baz();
} That said, AnyRef specialization is currently turned off, so the only specialization available is apply$mcI$sp but I think the point still stands. I only checked this bug because I'm trying to go through and close old specialization bugs that might now be fixed in master. |
The summary (title) of this issue is fairly involved but I couldn't find better one. I think it's the best to present code at this point:
We are interested in apply method of Baz class. Let's see the javap output:
we see here that specialized overrides are missing so default specialized implementations will be used (from Inter class) that forward to Foo$class and thus box.
This problem is caused by the fact that AnyRef specialization is a bit more tricky than specialization on primitive types. When we specialize on AnyRef and then we check if given type argument for specialized type parameter is valid we have to use subtyping relationship instead of equality. The relevant piece of code is here:
https://github.com/scala/scala/blob/39f01d4f48e59c2037a3af759eb6d55d0da50e70/src/compiler/scala/tools/nsc/transform/SpecializeTypes.scala#L162
The text was updated successfully, but these errors were encountered: