@@ -36,12 +36,12 @@ import scala.quoted._
3636inline def assert (expr : => Boolean ): Unit =
3737 $ { assertImpl(' expr ) }
3838
39- def assertImpl (expr : Expr [Boolean ]) = ' {
39+ def assertImpl (expr : Expr [Boolean ])( given QuoteContext ) = ' {
4040 if (! $expr)
4141 throw new AssertionError (s " failed assertion: ${$ { showExpr(expr) }}" )
4242}
4343
44- def showExpr (expr : Expr [Boolean ]): Expr [String ] =
44+ def showExpr (expr : Expr [Boolean ])( given QuoteContext ) : Expr [String ] =
4545 ' { " <some source code>" } // Better implementation later in this document
4646```
4747
@@ -238,22 +238,23 @@ Running `compile(letExp, Map())` would yield the following Scala code:
238238' { val y = 3 ; (2 + y) + 4 }
239239```
240240The 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() ` .
242242Shouldn’t ` n ` be quoted? In fact this would not
243243work since replacing ` n ` by ` 'n ` in the clause would not be phase
244244correct.
245245
246- The ` toExpr ` extension method is defined in package ` quoted ` :
246+ The ` Expr.apply ` method is defined in package ` quoted ` :
247247``` scala
248248package quoted
249249
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)
252253 ...
253254}
254255```
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 ` .
257258
258259Dotty comes with given instances of ` Liftable ` for
259260several types including ` Boolean ` , ` String ` , and all primitive number
0 commit comments