Skip to content

Remove element type from mutable.ArraySeq.(elemTag|array)#6648

Merged
lrytz merged 1 commit intoscala:2.13.xfrom
szeiger:issue/10851
May 30, 2018
Merged

Remove element type from mutable.ArraySeq.(elemTag|array)#6648
lrytz merged 1 commit intoscala:2.13.xfrom
szeiger:issue/10851

Conversation

@szeiger
Copy link
Contributor

@szeiger szeiger commented May 15, 2018

ArraySeq can be boxed or unboxed for primitives and could have been
created with an Array[AnyRef] for arbitrary reference types, so we
cannot guarantee any specific element type for the backing array.

Fixes scala/bug#10851

@scala-jenkins scala-jenkins added this to the 2.13.0-M5 milestone May 15, 2018
Copy link
Member

@lrytz lrytz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have the same issue for immutable.ArraySeq

scala> collection.immutable.ArraySeq.untagged(1,2,3).unsafeArray
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [I
  ... 33 elided

Could you also add some tests?

ArraySeqs (both mutable and immutable) can be boxed or unboxed for
primitives and could have been created with an `Array[AnyRef]` for
arbitrary reference types, so we cannot guarantee any specific element
type for the backing array.
@szeiger
Copy link
Contributor Author

szeiger commented May 30, 2018

Updated to cover immutable.ArraySeq, too.

/** The wrapped mutable `Array` that backs this `ArraySeq`. Any changes to this array will break
* the expected immutability. */
def unsafeArray: Array[A @uncheckedVariance]
// uncheckedVariance should be safe: Array[A] for reference types A is covariant at the JVM level. Array[A] for
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So much for my assumptions...

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

Successfully merging this pull request may close these issues.

3 participants