Skip to content

Commit f0fbf4b

Browse files
Merge pull request #5543 from dotty-staging/add-tasty-list-of-expr-ops
Add `List[Expr[T]]` to `Expr[List[T]]` conversion in the library
2 parents 24a2798 + 8c0178e commit f0fbf4b

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package scala
2+
3+
package object quoted {
4+
5+
implicit class LiftExprOps[T](val x: T) extends AnyVal {
6+
def toExpr(implicit ev: Liftable[T]): Expr[T] = ev.toExpr(x)
7+
}
8+
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+
}
18+
}

library/src/scala/quoted/package.scala

Lines changed: 0 additions & 9 deletions
This file was deleted.

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)