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

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

Merged
merged 1 commit into from
May 30, 2018

Conversation

szeiger
Copy link
Member

@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
Member Author

szeiger commented May 30, 2018

Updated to cover immutable.ArraySeq, too.


override def iterableFactory: SeqFactory[ArraySeq] = ArraySeq.untagged

/** 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
Member 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
3 participants