Skip to content

Commit 40fa0a2

Browse files
committed
Add quoted.Liftable[ClassTag[T]] to the stdlib
1 parent 1e7836d commit 40fa0a2

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

library/src-bootstrapped/scala/quoted/Liftable.scala

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

48+
given ClassTagIsLiftable[T: Type] as Liftable[ClassTag[T]] = new Liftable[ClassTag[T]] {
49+
def toExpr(ct: ClassTag[T]): given QuoteContext => Expr[ClassTag[T]] =
50+
'{ ClassTag[T](${ct.runtimeClass.toExpr}) }
51+
}
52+
4853
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-
}
54+
def toExpr(arr: Array[T]): given QuoteContext => Expr[Array[T]] =
55+
'{ Array[T](${arr.toSeq.toExpr}: _*)(${the[ClassTag[T]].toExpr}) }
5356
}
5457

5558
given ArrayOfBooleanIsLiftable as Liftable[Array[Boolean]] = new Liftable[Array[Boolean]] {

0 commit comments

Comments
 (0)