Skip to content

Commit 63c7f73

Browse files
committed
Add toExpr extension method to all liftable classes
Requires importing Liftable._
1 parent c2e5011 commit 63c7f73

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

library/src/scala/quoted/Liftable.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ abstract class Liftable[T] {
1414
*/
1515
object Liftable {
1616

17+
implicit class LiftExprOps[T](val x: T) extends AnyVal {
18+
def toExpr(implicit liftable: Liftable[T]): Expr[T] = liftable.toExpr(x)
19+
}
20+
1721
final class ConstantExpr[T] private[Liftable](val value: T) extends Expr[T] {
1822
override def toString: String = s"Expr($value)"
1923
}

tests/pos/quote-lift.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import scala.quoted._
2+
3+
object Test {
4+
'{ ~(1: Expr[Int]) }
5+
6+
'{ ~implicitly[Liftable[Int]].toExpr(1) }
7+
8+
{
9+
import Liftable._
10+
11+
'{ ~IntIsLiftable.toExpr(1) }
12+
13+
'{ ~1.toExpr }
14+
15+
}
16+
17+
18+
}

0 commit comments

Comments
 (0)