File tree Expand file tree Collapse file tree 1 file changed +13
-9
lines changed
docs/docs/reference/metaprogramming Expand file tree Collapse file tree 1 file changed +13
-9
lines changed Original file line number Diff line number Diff line change @@ -20,8 +20,8 @@ guarantees and may fail at macro expansion time, hence additional explicit
2020checks must be done.
2121
2222To provide reflection capabilities in macros we need to add an implicit
23- parameter of type ` scala.quoted.QuoteContext ` and import ` tasty._ ` from it in the scope where it
24- is used.
23+ parameter of type ` scala.quoted.QuoteContext ` and import ` tasty._ ` from it in
24+ the scope where it is used.
2525
2626``` scala
2727import scala .quoted ._
@@ -47,18 +47,22 @@ def natConstImpl(x: Expr[Int]) given (qctx: QuoteContext): Expr[Int] = {
4747 import qctx .tasty ._
4848 val xTree : Term = x.unseal
4949 xTree match {
50- case Term .Literal (Constant .Int (n)) =>
51- if (n <= 0 )
52- QuoteError (" Parameter must be natural number" )
53- n.toExpr
50+ case Inlined (_, _, Literal (Constant (n : Int ))) =>
51+ if (n <= 0 ) {
52+ qctx.error(" Parameter must be natural number" )
53+ ' {0 }
54+ } else {
55+ xTree.seal.cast[Int ]
56+ }
5457 case _ =>
55- QuoteError (" Parameter must be a known constant" )
58+ qctx.error(" Parameter must be a known constant" )
59+ ' {0 }
5660 }
5761}
5862```
5963
60- To easily know which extractors are needed, the ` qctx.tasty.Term.show ` method
61- returns the string representation of the extractors.
64+ To easily know which extractors are needed, the ` showExtractors ` method on a
65+ ` qctx.tasty.Term ` returns the string representation of the extractors.
6266
6367The method ` qctx.tasty.Term.seal[T] ` provides a way to go back to a
6468` quoted.Expr[Any] ` . Note that the type is ` Expr[Any] ` . Consequently, the type
You can’t perform that action at this time.
0 commit comments