Skip to content

Commit 52a237d

Browse files
committed
Add quoted.Liftable[Array[T]] to the stdlib
1 parent 89ad39b commit 52a237d

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

library/src/scala/quoted/Liftable.scala

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,14 @@ object Liftable {
4545
}
4646
}
4747

48-
given [T: Type: Liftable: ClassTag] as Liftable[IArray[T]] = new Liftable[IArray[T]] {
48+
given ArrayIsLiftable[T: Type: Liftable: ClassTag] as Liftable[Array[T]] = new Liftable[Array[T]] {
49+
def toExpr(arr: Array[T]): given QuoteContext => Expr[Array[T]] = '{
50+
val array = new Array[T](${arr.length.toExpr})(ClassTag(${the[ClassTag[T]].runtimeClass.toExpr}))
51+
${ Expr.block(List.tabulate(arr.length)(i => '{ array(${i.toExpr}) = ${arr(i).toExpr} }), '{ array }) }
52+
}
53+
}
54+
55+
given IArrayIsLiftable[T: Type: Liftable: ClassTag] as Liftable[IArray[T]] = new Liftable[IArray[T]] {
4956
def toExpr(iarray: IArray[T]): given QuoteContext => Expr[IArray[T]] = '{
5057
val array = new Array[T](${iarray.length.toExpr})(ClassTag(${the[ClassTag[T]].runtimeClass.toExpr}))
5158
${ Expr.block(List.tabulate(iarray.length)(i => '{ array(${i.toExpr}) = ${iarray(i).toExpr} }), '{ array.asInstanceOf[IArray[T]] }) }

tests/run-with-compiler/quote-lib.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,9 @@ object Test {
6868
val iarray: IArray[Int] = IArray(1, 2, 3)
6969
val liftedIArray: Expr[IArray[Int]] = iarray
7070

71+
val array: Array[Int] = Array(1, 2, 3)
72+
val liftedArray: Expr[Array[Int]] = array
73+
7174
val some: Option[Int] = Some(2)
7275
val none: Option[Int] = Some(2)
7376
val liftedSome: Expr[Option[Int]] = some

0 commit comments

Comments
 (0)