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

@newsubtype instances cannot be used in Arrays #35

Open
velvia opened this issue Jul 2, 2018 · 1 comment
Open

@newsubtype instances cannot be used in Arrays #35

velvia opened this issue Jul 2, 2018 · 1 comment

Comments

@velvia
Copy link

velvia commented Jul 2, 2018

version 0.4.2.

object Test {
  @newsubtype case class VectorPointer(addr: Long)
 }

scala> new Array[Test.VectorPointer](10)
<console>:12: error: cannot find class tag for element type Test.VectorPointer
       new Array[Test.VectorPointer](10)
@carymrobbins
Copy link
Member

I actually have a wip branch (10-as-array) which improves Array support for newtypes. At this point though, you should be fine to cast so long as you know that the types are correct. So the following may be a workaround for you -

Array[Long](10).asInstanceOf[Array[VectorPointer]]

You could wrap this into a method to improve safety -

@newsubtype case class VectorPointer(addr: Long)
object VectorPointer {
  def wrapArray(a: Array[Long]): Array[VectorPointer] = a.asInstanceOf[Array[VectorPointer]]
  def unwrapArray(a: Array[VectorPointer]): Array[Long] = a.asInstanceOf[Array[Long]]
}

scala> VectorPointer.wrapArray(Array(10))
res0: Array[VectorPointer] = Array(10)

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