-
Notifications
You must be signed in to change notification settings - Fork 3.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
Deal with special case for Array[Unit] in Array.{copyOf,copyAs} #6829
Conversation
Thanks to @mkeskells for spotting that we were filling |
That's not false, but fixing this seems like a drop in the ocean. There are many other cases where constructing an array of $ ~/opt/scala-2.13.0-M4/bin/scala
Welcome to Scala 2.13.0-M4 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_40).
Type in expressions for evaluation. Or try :help.
scala> val a = new Array[Unit](5)
a: Array[Unit] = Array((), (), (), (), ()) // This is a lie
scala> a.asInstanceOf[Array[scala.runtime.BoxedUnit]](0)
res0: scala.runtime.BoxedUnit = null The lie comes from |
src/library/scala/Array.scala
Outdated
@@ -122,7 +122,9 @@ object Array { | |||
* @see `java.util.Arrays#copyOf` | |||
*/ | |||
def copyOf[A](original: Array[A], newLength: Int): Array[A] = (original match { | |||
case x: Array[AnyRef] => java.util.Arrays.copyOf(x, newLength) | |||
case x: Array[AnyRef] => | |||
if (x.getClass.getComponentType == classOf[BoxedUnit]) newUnitArray(newLength).asInstanceOf[Array[A]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason not to use the usual match case x: Array[BoxedUnit]
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've changed to use that. The only tricky part is that it needs to precede the match on _: Array[AnyRef]
due to array covariance in the VM.
d365711
to
7fca0f3
Compare
BTW xuwei-k@a9761ba 🤔 |
@xuwei-k The JVM doesn't have |
No description provided.