Skip to content

Commit a59f576

Browse files
Update macros.md
PR feedback
1 parent f9320fc commit a59f576

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

docs/docs/reference/metaprogramming/macros.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,14 @@ def to[T, R](f: Expr[T] => Expr[R])(using t: Type[T])(using Type[R], Quotes): Ex
197197
```
198198

199199
In this version of `to`, the type of `x` is now the result of
200-
splicing the `Type` value `t`. This operation _is_ splice correct -- there
201-
is one quote and one splice between the use of `t` and its definition.
200+
inserting the type `Type[T]` and selecting its `Underlying `.
201+
202+
To avoid clutter, the compiler converts any type reference to
203+
a type `T` in subsequent phases to `summon[Type[T]].Underlying`.
204+
205+
And to avoid duplication it does it once per type, and creates
206+
an alias for that type at the start of the quote.
202207

203-
To avoid clutter, the Scala implementation tries to convert any type
204-
reference to a type `T` in subsequent phases to a type-splice, by rewriting `T` to `summon[Type[T]].Underlying`.
205208
For instance, the user-level definition of `to`:
206209

207210
```scala
@@ -213,7 +216,10 @@ would be rewritten to
213216

214217
```scala
215218
def to[T, R](f: Expr[T] => Expr[R])(using t: Type[T], r: Type[R])(using Quotes): Expr[T => R] =
216-
'{ (x: t.Underlying) => ${ f('x) } }
219+
'{
220+
type T = t.Underlying
221+
(x: T) => ${ f('x) }
222+
}
217223
```
218224

219225
The `summon` query succeeds because there is a given instance of

0 commit comments

Comments
 (0)