-
Notifications
You must be signed in to change notification settings - Fork 31
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
Support Array casting #10
Comments
/cc @joroKr21 The encoding of the newtype macros in v0.4.0 now allow for scala> Array(1,2,3).asInstanceOf[Array[Foo]]
res0: Array[Foo] = Array(1, 2, 3)
scala> res0.getClass
res1: Class[_ <: Array[Foo]] = class [I
scala> res0.head
res2: Foo = 1 I have also started work on the 10-as-array branch which introduces the scala> import io.estatico.newtype.macros._, io.estatico.newtype.arrays._
scala> @newtype case class Foo(x: Int)
scala> AsArray(Foo(1), Foo(2))
res0: Array[Foo] = Array(1, 2)
scala> res0.getClass
res1: Class[_ <: Array[Foo]] = class [I
scala> res0.head
res2: Foo = 1
scala> AsArray.empty[Foo]
res3: Array[Foo] = Array()
scala> res3.getClass
res4: Class[_ <: Array[Foo]] = class [I
scala> AsArray.downcast(res0)
res8: Array[Int] = Array(1, 2)
scala> res8.head
res9: Int = 1
scala> Array(1,2,3)
res10: Array[Int] = Array(1, 2, 3)
scala> AsArray.upcast(res10): Array[Foo]
res12: Array[Foo] = Array(1, 2, 3)
scala> AsArray.upcast[Foo](res10)
res13: Array[Foo] = Array(1, 2, 3) |
I think we might be able to now support |
@alexknvl pointed out that it's possible to encode newtypes in such a way that casting Arrays with
asInstanceOf
will work (which means Coercible can work too).Here's a simple adaptation from his solution to demonstrate a failing test case.
The text was updated successfully, but these errors were encountered: