Skip to content

new Array[AnyRef](...).asInstanceOf[Array[T]] not supported #237

Description

@VladUreche

... for a good reason. But we need to either issue errors of handle it:

scala> def foo[T](t: T) = {
     |   val arr = new Array[AnyRef](10).asInstanceOf[Array[T]]
     |   arr(0) = t
     | }
foo: [T](t: T)Unit

scala> foo(4)

But when we add the @miniboxed annotation:

scala> def foo[@miniboxed T](t: T) = {
     |   val arr = new Array[AnyRef](10).asInstanceOf[Array[T]]
     |   arr(0) = t
     | }
foo: [T](t: T)Unit

scala> foo(4)
java.lang.ClassCastException: [Ljava.lang.Object; cannot be cast to [I
  at miniboxing.runtime.MiniboxArrayLong.mbarray_update_minibox(MiniboxArrayLong.java:57)
  at .foo$n$J(<console>:9)
  ... 33 elided

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions