Skip to content

Commit b526788

Browse files
committed
Update Unliftable API
* Align with Liftable API definitions * Simplify implementation signatures
1 parent 5ee8777 commit b526788

File tree

8 files changed

+48
-48
lines changed

8 files changed

+48
-48
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ object Expr {
5656
* Otherwise returns the `Some` of the value.
5757
*/
5858
def unlift(using qctx: QuoteContext, unlift: Unliftable[T]): Option[T] =
59-
unlift(expr)
59+
unlift.fromExpr(expr)
6060

6161
/** Return the unlifted value of this expression.
6262
*
@@ -67,7 +67,7 @@ object Expr {
6767
def reportError =
6868
val msg = s"Expected a known value. \n\nThe value of: ${expr.show}\ncould not be unlifted using $unlift"
6969
report.throwError(msg, expr)
70-
unlift(expr).getOrElse(reportError)
70+
unlift.fromExpr(expr).getOrElse(reportError)
7171
end extension
7272

7373
/** `e.betaReduce` returns an expression that is functionally equivalent to `e`,

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

Lines changed: 37 additions & 37 deletions
Large diffs are not rendered by default.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object Unlifted {
1313
* ```
1414
*/
1515
def unapply[T](expr: Expr[T])(using unlift: Unliftable[T], qxtc: QuoteContext): Option[T] =
16-
unlift(expr)
16+
unlift.fromExpr(expr)
1717

1818
/** Matches literal sequence of literal constant value expressions and return a sequence of values.
1919
*

tests/neg-macros/inline-macro-staged-interpreter/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ object E {
99
def impl[T: Type](x: Expr[E[T]]) (using QuoteContext): Expr[T] = x.unliftOrError.lift
1010

1111
implicit def ev1[T: Type]: Unliftable[E[T]] = new Unliftable {
12-
def apply(x: Expr[E[T]]) (using QuoteContext): Option[E[T]] = x match {
12+
def fromExpr(x: Expr[E[T]]) = x match {
1313
case '{ I(${Const(n)}) } => Some(I(n).asInstanceOf[E[T]])
1414
case '{ Plus[T](${Value(x)}, ${Value(y)})(using $op) } if op.matches('{Plus2.IPlus}) => Some(Plus(x, y)(using Plus2.IPlus.asInstanceOf[Plus2[T]]).asInstanceOf[E[T]])
1515
case _ => None

tests/run-macros/inline-macro-staged-interpreter/Macro_1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ object E {
1010
expr.unliftOrError.lift
1111

1212
implicit def ev1[T: Type]: Unliftable[E[T]] = new Unliftable { // TODO use type class derivation
13-
def apply(x: Expr[E[T]]) (using QuoteContext): Option[E[T]] = (x match {
13+
def fromExpr(x: Expr[E[T]]) = (x match {
1414
case '{ I(${Const(n)}) } => Some(I(n))
1515
case '{ D(${Const(n)}) } => Some(D(n))
1616
case '{ Plus[Int](${Value(x)}, ${Value(y)})(using $op) } => Some(Plus(x, y)(using Plus2.IPlus))

tests/run-staging/quote-valueof-list.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ object Test {
88
def main(args: Array[String]): Unit = withQuoteContext {
99

1010
implicit def UnliftableInt: Unliftable[Int] = new {
11-
def apply(n: Expr[Int])(using QuoteContext): Option[Int] = n match {
11+
def fromExpr(n: Expr[Int]) = n match {
1212
case '{ 0 } => Some(0)
1313
case '{ 1 } => Some(1)
1414
case '{ 2 } => Some(1)
@@ -17,15 +17,15 @@ object Test {
1717
}
1818

1919
implicit def UnliftableBoolean: Unliftable[Boolean] = new Unliftable[Boolean] {
20-
def apply(b: Expr[Boolean])(using QuoteContext): Option[Boolean] = b match {
20+
def fromExpr(b: Expr[Boolean]) = b match {
2121
case '{ true } => Some(true)
2222
case '{ false } => Some(false)
2323
case _ => None
2424
}
2525
}
2626

2727
implicit def UnliftableList[T: Unliftable: Type]: Unliftable[List[T]] = new {
28-
def apply(xs: Expr[List[T]])(using QuoteContext): Option[List[T]] = (xs: Expr[Any]) match {
28+
def fromExpr(xs: Expr[List[T]]) = (xs: Expr[Any]) match {
2929
case '{ ($xs1: List[T]).::($x) } =>
3030
for { head <- x.unlift; tail <- xs1.unlift }
3131
yield head :: tail
@@ -35,7 +35,7 @@ object Test {
3535
}
3636

3737
implicit def UnliftableOption[T: Unliftable: Type]: Unliftable[Option[T]] = new {
38-
def apply(expr: Expr[Option[T]])(using QuoteContext): Option[Option[T]] = expr match {
38+
def fromExpr(expr: Expr[Option[T]]) = expr match {
3939
case '{ Some[T]($x) } => for (v <- x.unlift) yield Some(v)
4040
case '{ None } => Some(None)
4141
case _ => None

0 commit comments

Comments
 (0)