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

primitive arrays and varargs #3304

Closed
scabug opened this issue Apr 15, 2010 · 5 comments
Closed

primitive arrays and varargs #3304

scabug opened this issue Apr 15, 2010 · 5 comments
Assignees

Comments

@scabug
Copy link

scabug commented Apr 15, 2010

First example doesn't work, should I think. All the other variations do work.

scala> "%d %d".format(Array(5, 10): _*)
java.lang.ClassCastException: [I cannot be cast to [Ljava.lang.Object;

scala> "%d %d".format(Array[Integer](5, 10): _*)
warning: there were deprecation warnings; re-run with -deprecation for details
res7: String = 5 10

scala> "%d %d %d".format((Array(1,2,3): Seq[Int]) : _*)
res8: String = 1 2 3

scala> "%d %d".format(5, 10) 
res9: String = 5 10
@scabug
Copy link
Author

scabug commented Apr 15, 2010

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

@scabug
Copy link
Author

scabug commented Apr 19, 2010

@dubochet said:
The first line gets compiled to:

Predef.augmentString("%d %d").format(Predef.genericWrapArray(
  Array.apply(5, Predef.wrapIntArray(Array[Int]{10})).$$asInstanceOf[Array[java.lang.Object]]()
));

Which looks strange (why the wrapIntArray on the second argument only?)

@scabug
Copy link
Author

scabug commented Apr 19, 2010

@paulp said:
Replying to [comment:2 dubochet]:

Which looks strange (why the wrapIntArray on the second argument only?)

Turns out that's because all the scala.Array primitive applies look like this:

  def apply(x: Int, xs: Int*): Array[Int] = {

Presumably because otherwise all the overloads look the same after erasure.

I propose that the thing it's trying to do, which doesn't work in the fashion it's trying:

$$asInstanceOf[Array[java.lang.Object]]

should exist as a method on WrappedArray with a name like "toBoxed". It would be plus or minus:

def toBoxed: Array[AnyRef] = array map (_.asInstanceOf[AnyRef])

@scabug
Copy link
Author

scabug commented Apr 19, 2010

@paulp said:
...returns WrappedArray[AnyRef] I guess, but you get the gist.

@scabug
Copy link
Author

scabug commented May 19, 2010

@odersky said:
(In r21981) Closes #3304. Review by extempore.

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

No branches or pull requests

2 participants