File tree Expand file tree Collapse file tree 1 file changed +7
-6
lines changed
docs/docs/reference/metaprogramming Expand file tree Collapse file tree 1 file changed +7
-6
lines changed Original file line number Diff line number Diff line change @@ -36,12 +36,12 @@ import scala.quoted._
36
36
inline def assert (expr : => Boolean ): Unit =
37
37
$ { assertImpl(' expr ) }
38
38
39
- def assertImpl (expr : Expr [Boolean ]) = ' {
39
+ def assertImpl (expr : Expr [Boolean ])( given qctx : QuoteContext ) = ' {
40
40
if (! $expr)
41
41
throw new AssertionError (s " failed assertion: ${$ { showExpr(expr) }}" )
42
42
}
43
43
44
- def showExpr (expr : Expr [Boolean ]): Expr [String ] =
44
+ def showExpr (expr : Expr [Boolean ])( given qctx : QuoteContext ) : Expr [String ] =
45
45
' { " <some source code>" } // Better implementation later in this document
46
46
```
47
47
@@ -238,17 +238,18 @@ Running `compile(letExp, Map())` would yield the following Scala code:
238
238
' { val y = 3 ; (2 + y) + 4 }
239
239
```
240
240
The body of the first clause, ` case Num(n) => Expr(n) ` , looks suspicious. ` n `
241
- is declared as an ` Int ` , yet it is converted to an ` Expr[Int] ` with ` toExpr ` .
241
+ is declared as an ` Int ` , yet it is converted to an ` Expr[Int] ` with ` Expr() ` .
242
242
Shouldn’t ` n ` be quoted? In fact this would not
243
243
work since replacing ` n ` by ` 'n ` in the clause would not be phase
244
244
correct.
245
245
246
- The ` toExpr ` extension method is defined in package ` quoted ` :
246
+ The ` Expr ` method is defined in package ` quoted ` :
247
247
``` scala
248
248
package quoted
249
249
250
- given {
251
- def (x : T ) toExpr[T : Liftable ](given QuoteContext ): Expr [T ] = summon[Liftable [T ]].toExpr(x)
250
+ object Expr {
251
+ ...
252
+ def apply [T : Liftable ](x : T )(given QuoteContext ): Expr [T ] = summon[Liftable [T ]].toExpr(x)
252
253
...
253
254
}
254
255
```
You can’t perform that action at this time.
0 commit comments