Skip to content

Commit 8c0178e

Browse files
committed
Add List[Expr[T]] to Expr[List[T]] conversion in the library
1 parent 26cec65 commit 8c0178e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

library/src-scala3/scala/quoted/package.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,13 @@ package object quoted {
66
def toExpr(implicit ev: Liftable[T]): Expr[T] = ev.toExpr(x)
77
}
88

9+
implicit class ListOfExprOps[T](val list: List[Expr[T]]) extends AnyVal {
10+
def toExprOfList(implicit ev: Type[T]): Expr[List[T]] = {
11+
def rec(list: List[Expr[T]]): Expr[List[T]] = list match {
12+
case x :: xs => '{ (~x) :: (~rec(xs)) }
13+
case Nil => '(Nil)
14+
}
15+
rec(list)
16+
}
17+
}
918
}

tests/run-separate-compilation/xml-interpolation-2/XmlQuote_1.scala

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,7 @@ object XmlQuote {
5656
// [a0, ...]: Any*
5757
val args2: Expr[List[Any]] = args.unseal.underlyingArgument match {
5858
case Typed(Repeated(args0), _) => // statically known args, make list directly
59-
def liftListOfAny(lst: List[Expr[Any]]): Expr[List[Any]] = lst match {
60-
case x :: xs => '{ ~x :: ~liftListOfAny(xs) }
61-
case Nil => '(Nil)
62-
}
63-
liftListOfAny(args0.map(_.seal[Any]))
59+
args0.map(_.seal[Any]).toExprOfList
6460
case _ =>
6561
'((~args).toList)
6662

0 commit comments

Comments
 (0)