Skip to content

Commit 005a65e

Browse files
Merge pull request #8545 from dotty-staging/fix-macro-docs
Fix macro docs
2 parents b08d746 + 3941b59 commit 005a65e

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

docs/docs/reference/metaprogramming/macros.md

+6-6
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.
@@ -671,7 +671,7 @@ optimize {
671671

672672
```scala
673673
def sum(args: Int*): Int = args.sum
674-
inline def optimize(arg: Int): Int = ${ optimizeExpr('arg) }
674+
inline def optimize(inline arg: Int): Int = ${ optimizeExpr('arg) }
675675
private def optimizeExpr(body: Expr[Int])(using QuoteContext): Expr[Int] = body match {
676676
// Match a call to sum without any arguments
677677
case '{ sum() } => Expr(0)
@@ -717,7 +717,7 @@ This might be used to then perform an implicit search as in:
717717

718718

719719
```scala
720-
inline def (sc: StringContext).showMe(inline args: Any*): String = ${ showMeExpr('sc, 'args) }
720+
inline def (inline sc: StringContext).showMe(inline args: Any*): String = ${ showMeExpr('sc, 'args) }
721721

722722
private def showMeExpr(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using qctx: QuoteContext): Expr[String] = {
723723
argsExpr match {

0 commit comments

Comments
 (0)