Skip to content

Commit 518135d

Browse files
Merge pull request #9219 from ShapelessCat/fix-doc-macros-function-references
Fix documentation
2 parents 9e1b2f3 + 877d633 commit 518135d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

docs/docs/reference/metaprogramming/macros.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,28 +183,28 @@ Types are not directly affected by the phase consistency principle.
183183
It is possible to use types defined at any level in any other level.
184184
But, if a type is used in a subsequent stage it will need to be lifted to a `Type`.
185185
The resulting value of `Type` will be subject to PCP.
186-
Indeed, the definition of `reflect` above uses `T` in the next stage, there is a
186+
Indeed, the definition of `to` above uses `T` in the next stage, there is a
187187
quote but no splice between the parameter binding of `T` and its
188188
usage. But the code can be rewritten by adding a binding of a `Type[T]` tag:
189189
```scala
190-
def reflect[T, U](f: Expr[T] => Expr[U])(using t: Type[T]): Expr[T => U] =
190+
def to[T, R: Type](f: Expr[T] => Expr[R])(using t: Type[T])(using QuoteContext): Expr[T => R] =
191191
'{ (x: $t) => ${ f('x) } }
192192
```
193-
In this version of `reflect`, the type of `x` is now the result of
193+
In this version of `to`, the type of `x` is now the result of
194194
splicing the `Type` value `t`. This operation _is_ splice correct -- there
195195
is one quote and one splice between the use of `t` and its definition.
196196

197197
To avoid clutter, the Scala implementation tries to convert any type
198198
reference to a type `T` in subsequent phases to a type-splice, by rewriting `T` to `${ summon[Type[T]] }`.
199-
For instance, the user-level definition of `reflect`:
199+
For instance, the user-level definition of `to`:
200200

201201
```scala
202-
def reflect[T: Type, U: Type](f: Expr[T] => Expr[U]): Expr[T => U] =
202+
def to[T: Type, R: Type](f: Expr[T] => Expr[R])(using QuoteContext): Expr[T => R] =
203203
'{ (x: T) => ${ f('x) } }
204204
```
205205
would be rewritten to
206206
```scala
207-
def reflect[T: Type, U: Type](f: Expr[T] => Expr[U]): Expr[T => U] =
207+
def to[T: Type, R: Type](f: Expr[T] => Expr[R])(using QuoteContext): Expr[T => R] =
208208
'{ (x: ${ summon[Type[T]] }) => ${ f('x) } }
209209
```
210210
The `summon` query succeeds because there is a given instance of

0 commit comments

Comments
 (0)