@@ -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 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 QuoteContext ) : Expr [String ] =
45
45
' { " <some source code>" } // Better implementation later in this document
46
46
```
47
47
@@ -238,22 +238,23 @@ 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.apply ` 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
```
255
- The extension says that values of types implementing the ` Liftable ` type class can be
256
- converted ("lifted") to ` Expr ` values using ` toExpr ` , provided a given import of ` scala.quoted._ ` is in scope .
256
+ This method says that values of types implementing the ` Liftable ` type class can be
257
+ converted ("lifted") to ` Expr ` values using ` Expr.apply ` .
257
258
258
259
Dotty comes with given instances of ` Liftable ` for
259
260
several types including ` Boolean ` , ` String ` , and all primitive number
0 commit comments