Skip to content

Commit d85cb98

Browse files
committed
Update Unliftable/unlift/unliftOrError
1 parent b08d746 commit d85cb98

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

docs/docs/reference/metaprogramming/macros.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ either a constant or is a parameter that will be a constant when instantiated. T
433433
aspect is also important for macro expansion.
434434

435435
To get values out of expressions containing constants `Expr` provides the method
436-
`getValue` (or `value`). This will convert the `Expr[T]` into a `Some[T]` (or `T`) when the
436+
`unlift` (or `unliftOrError`). This will convert the `Expr[T]` into a `Some[T]` (or `T`) when the
437437
expression contains value. Otherwise it will retrun `None` (or emit an error).
438438
To avoid having incidental val bindings generated by the inlining of the `def`
439439
it is recommended to use an inline parameter. To illustrate this, consider an
@@ -442,7 +442,7 @@ implementation of the `power` function that makes use of a statically known expo
442442
inline def power(x: Double, inline n: Int) = ${ powerCode('x, 'n) }
443443

444444
private def powerCode(x: Expr[Double], n: Expr[Int])(using QuoteContext): Expr[Double] =
445-
n.getValue match
445+
n.unlift match
446446
case Some(m) => powerCode(x, m)
447447
case None => '{ Math.pow($x, $y) }
448448

@@ -604,7 +604,7 @@ inline method that can calculate either a value of type `Int` or a value of type
604604
inline def defaultOf(inline str: String) <: Any = ${ defaultOfImpl('str) }
605605

606606
def defaultOfImpl(strExpr: Expr[String])(using QuoteContext): Expr[Any] =
607-
strExpr.value match
607+
strExpr.unliftOrError match
608608
case "int" => '{1}
609609
case "string" => '{"a"}
610610

@@ -633,7 +633,7 @@ It is possible to deconstruct or extract values out of `Expr` using pattern matc
633633
`scala.quoted` contains objects that can help extracting values from `Expr`.
634634

635635
* `scala.quoted.Const`/`scala.quoted.Consts`: matches an expression of a literal value (or list of values) and returns the value (or list of values).
636-
* `scala.quoted.Value`/`scala.quoted.Values`: matches an expression of a value (or list of values) and returns the value (or list of values).
636+
* `scala.quoted.Unlifted`: matches an expression of a value (or list of values) and returns the value (or list of values).
637637
* `scala.quoted.Varargs`: matches an explicit sequence of expresions and returns them. These sequences are useful to get individual `Expr[T]` out of a varargs expression of type `Expr[Seq[T]]`.
638638

639639
These could be used in the following way to optimize any call to `sum` that has statically known values.

0 commit comments

Comments
 (0)