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

If first specialized type is not primitive, the second is ignored. #3575

Closed
scabug opened this issue Jun 16, 2010 · 11 comments
Closed

If first specialized type is not primitive, the second is ignored. #3575

scabug opened this issue Jun 16, 2010 · 11 comments
Assignees

Comments

@scabug
Copy link

scabug commented Jun 16, 2010

I am not sure if this is a bug. The code runs fine. Given:

case class Two[@specialized A, @specialized B](v: A, w: B);
println(Two("Hello", 12).getClass().getName());
println(Two("Hello", "World").getClass().getName());
println(Two(12,12).getClass().getName());

In the first two cases the non-specialized version of Two is constructed. I expect the first println to show that the choice of a specialized version, for the second parameter (it is not). I expect the generic version to be chosen for the second (it is). I expect the specialized version to be chosen for the third (it is).

It's not clear to me whether this behavior is in the spec or not -- must all type parameters annotated with @specialized be primitive, in order for a primitive to be selected? Or is the mixture of object and primitive just not covered?

Apologies if this is covered somewhere already in the spec.

@scabug
Copy link
Author

scabug commented Jun 16, 2010

Imported From: https://issues.scala-lang.org/browse/SI-3575?orig=1
Reporter: @rossjudson

@scabug
Copy link
Author

scabug commented Jun 16, 2010

@rossjudson said:
Output looks something like this, showing the selection of the specialized type for the third print.

solo.Two
solo.Two
solo.Two$$mcII$$sp

@scabug
Copy link
Author

scabug commented Jun 29, 2010

@dragos said:
It is specced like that, but it seems more people complained about it, so it may change in the next version of Scala.

@scabug
Copy link
Author

scabug commented Aug 20, 2010

@adriaanm said:
(In r22802) closes #3575. stricter override checking for java members with default access: can only override such a member from the same package
cloneSymbol now preserves privateWithin -- need to reset it explicitly now when before it was assumed to be not to be carried over

rewrote accessibility in overriding checks so they're more readable, but hopefully with same semantics

review by odersky

@scabug
Copy link
Author

scabug commented Aug 20, 2010

@ijuma said:
I think Adriaan meant #3757 as can be seen in the follow-up commit r22803. Reopening.

@scabug
Copy link
Author

scabug commented Feb 16, 2012

@non said:
Interestingly, now that [@Specialize A] includes AnyRef, I would have expected this bug to be fixed.

But it seems that AnyRef specialization isn't working properly in this case at least. I see synthetic classes like Two$mcLI$sp being generated but not used. This may actually be a recently introduced bug breaking @SPEC(AnyRef) though; in which case, this bug might actually be fixed.

@scabug
Copy link
Author

scabug commented Feb 16, 2012

@non said:
I have opened #5488 to deal with the bugs with AnyRef specialization. When that bug is fixed, this bug might be fixed as well!

@scabug
Copy link
Author

scabug commented Feb 17, 2012

@non said (edited on Feb 17, 2012 11:38:44 PM UTC):
When AnyRef specialization is used explicitly (e.g. @specialized(Int, AnyRef)), this bug is fixed.

There's another bug, which is that as things stand [@specialized A] creates AnyRef specializations, but fails to use them. I'll look in this more closely.

@scabug
Copy link
Author

scabug commented Feb 19, 2012

@non said:
Now that #5500 is fixed, I have submitted a pull request which correctly interprets [@specialized A] as specializing on all types, including AnyRef. The only thing needed was to fix specializedOn to return a List of all the specialized types when the annotation didn't include any.

@scabug
Copy link
Author

scabug commented Feb 21, 2012

@non said:
This bug is fixed.

@scabug
Copy link
Author

scabug commented May 4, 2012

@magarciaEPFL said:

Now the specialized version is constructed in each case (ie the bug is fixed, closing it):

Welcome to Scala version 2.10.0-20120503-215615-f146d5826f (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_29).
Type in expressions to have them evaluated.
Type :help for more information.

scala> case class Two[@specialized A, @specialized B](v: A, w: B);
defined class Two

scala> println(Two("Hello", 12).getClass().getName());
$line3.$read$$iw$$iw$Two$mcLI$sp

scala> println(Two("Hello", "World").getClass().getName())
$line3.$read$$iw$$iw$Two

scala> println(Two(12,12).getClass().getName())
$line3.$read$$iw$$iw$Two$mcII$sp

scala>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants