Skip to content

Commit

Permalink
Rename Expr.unlifted to Expr.unliftOrError
Browse files Browse the repository at this point in the history
And remove all quoted deprecated API uses
  • Loading branch information
nicolasstucki committed Mar 13, 2020
1 parent ea27651 commit 7452bea
Show file tree
Hide file tree
Showing 41 changed files with 119 additions and 120 deletions.
8 changes: 4 additions & 4 deletions library/src/scala/quoted/Expr.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,22 +34,22 @@ class Expr[+T] private[scala] {
* Emits an error error and throws if the expression does not contain a value or contains side effects.
* Otherwise returns the value.
*/
@deprecated("Use Expr.unlifted", "0.23")
final def value[U >: T](using qctx: QuoteContext, unlift: Unliftable[U]): U = unlifted
@deprecated("Use Expr.unliftOrError", "0.23")
final def value[U >: T](using qctx: QuoteContext, unlift: Unliftable[U]): U = unliftOrError

/** Return the unlifted value of this expression.
*
* Emits an error error and throws if the expression does not contain a value or contains side effects.
* Otherwise returns the value.
*/
final def unlifted[U >: T](using qctx: QuoteContext, unlift: Unliftable[U]): U =
final def unliftOrError[U >: T](using qctx: QuoteContext, unlift: Unliftable[U]): U =
unlift(this).getOrElse(qctx.throwError(s"Expected a known value. \n\nThe value of: $show\ncould not be unlifted using $unlift", this))

/** Pattern matches `this` against `that`. Effectively performing a deep equality check.
* It does the equivalent of
* ```
* this match
* case '{...} => true // where the contens of the pattern are the contents of `that`
* case '{...} => true // where the contents of the pattern are the contents of `that`
* case _ => false
* ```
*/
Expand Down
2 changes: 1 addition & 1 deletion library/src/scala/quoted/matching/ConstSeq.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ object ConstSeq {
* }
* ```
*/
@deprecated("use scala.quoted.Varargs(scala.quoted.Const(_)) instead", "0.23.0")
@deprecated("use scala.quoted.Varargs(scala.quoted.Consts(_)) instead", "0.23.0")
def unapply[T](expr: Expr[Seq[T]])(using qctx: QuoteContext): Option[Seq[T]] =
import scala.quoted.Const
expr match
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object E {

inline def eval[T](inline x: E[T]): T = ${ impl('x) }

def impl[T: Type](x: Expr[E[T]]) (using QuoteContext): Expr[T] = x.value.lift
def impl[T: Type](x: Expr[E[T]]) (using QuoteContext): Expr[T] = x.unliftOrError.lift

implicit def ev1[T: Type]: Unliftable[E[T]] = new Unliftable {
def apply(x: Expr[E[T]]) (using QuoteContext): Option[E[T]] = x match {
Expand All @@ -18,7 +18,7 @@ object E {
}

object Value {
def unapply[T, U >: T](expr: Expr[T])(using Unliftable[U], QuoteContext): Option[U] = expr.getValue
def unapply[T, U >: T](expr: Expr[T])(using Unliftable[U], QuoteContext): Option[U] = expr.unlift
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/inline-option/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import scala.quoted._

object Macro {
def impl(opt: Expr[Option[Int]]) (using QuoteContext): Expr[Int] = opt.value match {
def impl(opt: Expr[Option[Int]]) (using QuoteContext): Expr[Int] = opt.unliftOrError match {
case Some(i) => Expr(i)
case None => '{-1}
}
Expand Down
44 changes: 22 additions & 22 deletions tests/neg-macros/inline-tuples-1/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,26 @@ import scala.quoted._
import scala.quoted.autolift.{given _}

object Macros {
def tup1(tup: Expr[Tuple1[Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup2(tup: Expr[Tuple2[Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup3(tup: Expr[Tuple3[Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup4(tup: Expr[Tuple4[Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup5(tup: Expr[Tuple5[Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup6(tup: Expr[Tuple6[Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup7(tup: Expr[Tuple7[Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup8(tup: Expr[Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup9(tup: Expr[Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup10(tup: Expr[Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup11(tup: Expr[Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup12(tup: Expr[Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup13(tup: Expr[Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup14(tup: Expr[Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup15(tup: Expr[Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup16(tup: Expr[Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup17(tup: Expr[Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup18(tup: Expr[Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup19(tup: Expr[Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup20(tup: Expr[Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup21(tup: Expr[Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup22(tup: Expr[Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.value.productIterator.map(_.asInstanceOf[Int]).sum
def tup1(tup: Expr[Tuple1[Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup2(tup: Expr[Tuple2[Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup3(tup: Expr[Tuple3[Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup4(tup: Expr[Tuple4[Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup5(tup: Expr[Tuple5[Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup6(tup: Expr[Tuple6[Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup7(tup: Expr[Tuple7[Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup8(tup: Expr[Tuple8[Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup9(tup: Expr[Tuple9[Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup10(tup: Expr[Tuple10[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup11(tup: Expr[Tuple11[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup12(tup: Expr[Tuple12[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup13(tup: Expr[Tuple13[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup14(tup: Expr[Tuple14[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup15(tup: Expr[Tuple15[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup16(tup: Expr[Tuple16[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup17(tup: Expr[Tuple17[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup18(tup: Expr[Tuple18[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup19(tup: Expr[Tuple19[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup20(tup: Expr[Tuple20[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup21(tup: Expr[Tuple21[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
def tup22(tup: Expr[Tuple22[Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int, Int]]) (using QuoteContext): Expr[Int] = tup.unliftOrError.productIterator.map(_.asInstanceOf[Int]).sum
}
2 changes: 1 addition & 1 deletion tests/neg-macros/quote-error-2/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import quoted._
object Macro_1 {
inline def foo(inline b: Boolean): Unit = ${ fooImpl('b) }
def fooImpl(b: Expr[Boolean])(using QuoteContext): Expr[Unit] =
'{println(${msg(b.value)})}
'{println(${msg(b.unliftOrError)})}

def msg(b: Boolean)(using qctx: QuoteContext): Expr[String] =
if (b) '{"foo(true)"}
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/quote-error/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import quoted._
object Macro_1 {
inline def foo(inline b: Boolean): Unit = ${fooImpl('b)}
def fooImpl(b: Expr[Boolean])(using qctx: QuoteContext) : Expr[Unit] =
if (b.value) '{println("foo(true)")}
if (b.unliftOrError) '{println("foo(true)")}
else { qctx.error("foo cannot be called with false"); '{ ??? } }
}
2 changes: 1 addition & 1 deletion tests/neg-macros/quote-exception/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ import quoted._
object Macro_1 {
inline def foo(inline b: Boolean): Unit = ${fooImpl('b)}
def fooImpl(b: Expr[Boolean]) (using QuoteContext): Expr[Unit] =
if (b.value) '{println("foo(true)")}
if (b.unliftOrError) '{println("foo(true)")}
else ???
}
2 changes: 1 addition & 1 deletion tests/neg-macros/quote-whitebox/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import scala.quoted._

object Macros {
inline def defaultOf(inline str: String) <: Any = ${ defaultOfImpl('str) }
def defaultOfImpl(str: Expr[String]) (using QuoteContext): Expr[Any] = str.value match {
def defaultOfImpl(str: Expr[String]) (using QuoteContext): Expr[Any] = str.unliftOrError match {
case "int" => '{1}
case "string" => '{"a"}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/neg-macros/reflect-inline/assert_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ object api {
${ stripImpl('x) }

private def stripImpl(x: Expr[String])(using qctx: QuoteContext): Expr[String] =
Expr(x.value.stripMargin)
Expr(x.unliftOrError.stripMargin)

}
2 changes: 1 addition & 1 deletion tests/pos-macros/power-macro/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object PowerMacro {
inline def power(inline n: Long, x: Double) = ${powerCode('n, 'x)}

def powerCode(n: Expr[Long], x: Expr[Double]) (using QuoteContext): Expr[Double] =
powerCode(n.value, x)
powerCode(n.unliftOrError, x)

def powerCode(n: Long, x: Expr[Double])(using QuoteContext): Expr[Double] =
if (n == 0) '{1.0}
Expand Down
4 changes: 2 additions & 2 deletions tests/pos-macros/quote-nested-object/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@ object Macro {
inline def plus(inline n: Int, m: Int): Int = ${ plus('n, 'm) }

def plus(n: Expr[Int], m: Expr[Int]) (using QuoteContext): Expr[Int] =
if (n.value == 0) m
if (n.unliftOrError == 0) m
else '{ ${n} + $m }

object Implementation2 {

inline def plus(inline n: Int, m: Int): Int = ${ plus('n, 'm) }

def plus(n: Expr[Int], m: Expr[Int]) (using QuoteContext): Expr[Int] =
if (n.value == 0) m
if (n.unliftOrError == 0) m
else '{ ${n} + $m }
}
}
Expand Down
2 changes: 1 addition & 1 deletion tests/pos-macros/quote-whitebox-2/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ object Macro {
inline def charOrString(inline str: String) <: Any = ${ impl('str) }

def impl(strExpr: Expr[String]) (using QuoteContext)=
val str = strExpr.value
val str = strExpr.unliftOrError
if (str.length == 1) Expr(str.charAt(0)) else Expr(str)

}
2 changes: 1 addition & 1 deletion tests/pos-staging/quote-0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ object Macros {
inline def power(inline n: Int, x: Double) = ${ powerCode('n, 'x) }

def powerCode(n: Expr[Int], x: Expr[Double]) (using QuoteContext): Expr[Double] =
powerCode(n.value, x)
powerCode(n.unliftOrError, x)

def powerCode(n: Int, x: Expr[Double])(using QuoteContext): Expr[Double] =
if (n == 0) '{1.0}
Expand Down
6 changes: 3 additions & 3 deletions tests/run-macros/gestalt-type-toolbox-reflect/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ object TypeToolbox {
inline def fieldIn[T](inline mem: String): String = ${fieldInImpl('[T], 'mem)}
private def fieldInImpl(t: Type[_], mem: Expr[String])(using qctx: QuoteContext) : Expr[String] = {
import qctx.tasty._
val field = t.unseal.symbol.field(mem.value)
val field = t.unseal.symbol.field(mem.unliftOrError)
Expr(if field.isNoSymbol then "" else field.name)
}

Expand All @@ -58,7 +58,7 @@ object TypeToolbox {
inline def methodIn[T](inline mem: String): Seq[String] = ${methodInImpl('[T], 'mem)}
private def methodInImpl(t: Type[_], mem: Expr[String])(using qctx: QuoteContext) : Expr[Seq[String]] = {
import qctx.tasty._
Expr(t.unseal.symbol.classMethod(mem.value).map(_.name))
Expr(t.unseal.symbol.classMethod(mem.unliftOrError).map(_.name))
}

inline def methodsIn[T]: Seq[String] = ${methodsInImpl('[T])}
Expand All @@ -70,7 +70,7 @@ object TypeToolbox {
inline def method[T](inline mem: String): Seq[String] = ${methodImpl('[T], 'mem)}
private def methodImpl(t: Type[_], mem: Expr[String])(using qctx: QuoteContext) : Expr[Seq[String]] = {
import qctx.tasty._
Expr(t.unseal.symbol.method(mem.value).map(_.name))
Expr(t.unseal.symbol.method(mem.unliftOrError).map(_.name))
}

inline def methods[T]: Seq[String] = ${methodsImpl('[T])}
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/i4734/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object Macros {
${ unrolledForeachImpl('seq, 'f, 'unrollSize) }

def unrolledForeachImpl(seq: Expr[IndexedSeq[Int]], f: Expr[Int => Unit], unrollSizeExpr: Expr[Int]) (using QuoteContext): Expr[Unit] =
unrolledForeachImpl(seq, f, unrollSizeExpr.value)
unrolledForeachImpl(seq, f, unrollSizeExpr.unliftOrError)

def unrolledForeachImpl(seq: Expr[IndexedSeq[Int]], f: Expr[Int => Unit], unrollSize: Int)(using QuoteContext): Expr[Unit] = '{
val size = ($seq).length
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/i4735/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ object Macro {
while (i < size) {
println("<log> start loop")
${
for (j <- new UnrolledRange(0, unrollSize.value)) '{
for (j <- new UnrolledRange(0, unrollSize.unliftOrError)) '{
val element = ($seq)(i + ${j})
${Expr.betaReduce(f)('element)} // or `($f)(element)` if `f` should not be inlined
}
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/i4803/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import scala.quoted._

object PowerMacro {
def powerCode(x: Expr[Double], n: Expr[Long]) (using QuoteContext): Expr[Double] =
powerCode(x, n.value)
powerCode(x, n.unliftOrError)

def powerCode(x: Expr[Double], n: Long) (using QuoteContext): Expr[Double] =
if (n == 0) '{1.0}
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/i4803b/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import scala.quoted._

object PowerMacro {
def powerCode(x: Expr[Double], n: Expr[Long]) (using QuoteContext): Expr[Double] =
powerCode(x, n.value)
powerCode(x, n.unliftOrError)

def powerCode(x: Expr[Double], n: Long) (using QuoteContext): Expr[Double] =
if (n == 0) '{1.0}
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/i4803c/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import scala.quoted._

object PowerMacro {
def powerCode(x: Expr[Double], n: Expr[Long]) (using QuoteContext): Expr[Double] =
powerCode(x, n.value)
powerCode(x, n.unliftOrError)

def powerCode(x: Expr[Double], n: Long) (using QuoteContext): Expr[Double] =
if (n == 0) '{1.0}
Expand Down
2 changes: 1 addition & 1 deletion tests/run-macros/i5188a/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import scala.quoted.autolift.{given _}

object Lib {
inline def sum(inline args: Int*): Int = ${ impl('args) }
def impl(args: Expr[Seq[Int]]) (using QuoteContext): Expr[Int] = args.value.sum
def impl(args: Expr[Seq[Int]]) (using QuoteContext): Expr[Int] = args.unliftOrError.sum
}
4 changes: 2 additions & 2 deletions tests/run-macros/i6201/macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ inline def (inline x: String) strip: String =
${ stripImpl('x) }

def stripImpl(x: Expr[String])(using qctx: QuoteContext) : Expr[String] =
Expr(x.value.stripMargin)
Expr(x.unliftOrError.stripMargin)

inline def isHello(inline x: String): Boolean =
${ isHelloImpl('x) }

def isHelloImpl(x: Expr[String])(using qctx: QuoteContext) : Expr[Boolean] =
if (x.value == "hello") Expr(true) else Expr(false)
if (x.unliftOrError == "hello") Expr(true) else Expr(false)
2 changes: 1 addition & 1 deletion tests/run-macros/i6765-c/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ import scala.quoted.{given _}
inline def foo(inline n: Int) = ${fooImpl('n)}

def fooImpl(n: Expr[Int])(using qctx: QuoteContext) = {
val res = Expr.ofList(List.tabulate(n.value)(i => Expr("#" + i)))
val res = Expr.ofList(List.tabulate(n.unliftOrError)(i => Expr("#" + i)))
'{ ${Expr(res.show)} + "\n" + $res.toString + "\n" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ object E {
inline def eval[T](inline x: E[T]): T = ${ impl('x) }

def impl[T: Type](expr: Expr[E[T]]) (using QuoteContext): Expr[T] =
expr.value.lift
expr.unliftOrError.lift

implicit def ev1[T: Type]: Unliftable[E[T]] = new Unliftable { // TODO use type class derivation
def apply(x: Expr[E[T]]) (using QuoteContext): Option[E[T]] = (x match {
Expand All @@ -22,7 +22,7 @@ object E {
}

object Value {
def unapply[T, U >: T](expr: Expr[T])(using Unliftable[U], QuoteContext): Option[U] = expr.getValue
def unapply[T, U >: T](expr: Expr[T])(using Unliftable[U], QuoteContext): Option[U] = expr.unlift
}

}
Expand Down
4 changes: 2 additions & 2 deletions tests/run-macros/inline-option/Macro_1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import scala.quoted.autolift.{given _}

object Macros {

def impl(opt: Expr[Option[Int]]) (using QuoteContext): Expr[Int] = opt.value match {
def impl(opt: Expr[Option[Int]]) (using QuoteContext): Expr[Int] = opt.unliftOrError match {
case Some(i) => i
case None => '{-1}
}

def impl2(opt: Expr[Option[Option[Int]]]) (using QuoteContext): Expr[Int] = impl(opt.value.flatten)
def impl2(opt: Expr[Option[Option[Int]]]) (using QuoteContext): Expr[Int] = impl(opt.unliftOrError.flatten)

}
Loading

0 comments on commit 7452bea

Please sign in to comment.