Skip to content

Commit d65148f

Browse files
committed
Move LiftExprOps to quoted package
To use `import scala.quotes._` to import `toExpr` extension
1 parent 5616145 commit d65148f

21 files changed

+12
-28
lines changed

docs/docs/reference/principled-meta-programming.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -527,17 +527,17 @@ work since replacing `n` by `’n` in the clause would not be phase
527527
correct.
528528

529529
What happens instead "under the hood" is an extension method `toExpr` is added: `n.toExpr`
530-
is expanded to `new scala.quoted.Liftable.LiftExprOps(n).toExpr`. The `toExpr` extension
530+
is expanded to `new scala.quoted.LiftExprOps(n).toExpr`. The `toExpr` extension
531531
is defined in the companion object of class `Liftable` as follows:
532532

533-
object Liftable {
533+
package object quoted {
534534
implicit class LiftExprOps[T](val x: T) extends AnyVal {
535535
def toExpr(implicit ev: Liftable[T]): Expr[T] = ev.toExpr(x)
536536
}
537537
}
538538

539539
The extension says that values of types implementing the `Liftable` type class can be
540-
converted ("lifted") to `Expr` values using `toExpr` when `Liftable._` is imported.
540+
converted ("lifted") to `Expr` values using `toExpr` when `scala.quoted._` is imported.
541541
Dotty comes with instance definitions of `Liftable` for
542542
several types including `Boolean`, `String`, and all primitive number
543543
types. For example, `Int` values can be converted to `Expr[Int]`

library/src/scala/quoted/Liftable.scala

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@ abstract class Liftable[T] {
1515
* gives an alternative implementation using just the basic staging system.
1616
*/
1717
object Liftable {
18-
19-
implicit class LiftExprOps[T](val x: T) extends AnyVal {
20-
def toExpr(implicit ev: Liftable[T]): Expr[T] = ev.toExpr(x)
21-
}
22-
2318
implicit def BooleanIsLiftable: Liftable[Boolean] = (x: Boolean) => new ValueExpr(x)
2419
implicit def ByteLiftable: Liftable[Byte] = (x: Byte) => new ValueExpr(x)
2520
implicit def CharIsLiftable: Liftable[Char] = (x: Char) => new ValueExpr(x)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package scala
2+
3+
package object quoted {
4+
5+
implicit class LiftExprOps[T](val x: T) extends AnyVal {
6+
def toExpr(implicit ev: Liftable[T]): Expr[T] = ev.toExpr(x)
7+
}
8+
9+
}

tests/pos/i3916/Macro_1.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import scala.quoted._
2-
import scala.quoted.Liftable._
32

43
class FInterpolatorHelper(val sc: StringContext) extends AnyVal {
54
inline def ff(arg1: Any): String = ~FInterpolation.fInterpolation(sc, Seq('(arg1)))

tests/pos/quote-0.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import scala.quoted._
2-
import scala.quoted.Liftable._
32

43
import dotty.tools.dotc.quoted.Toolbox._
54

tests/pos/quote-interpolator-core/quoted_1.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import scala.quoted._
2-
import scala.quoted.Liftable._
32

43
// This test checks the correct interpretation of the inlined value class
54

tests/pos/quote-lift.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import scala.quoted._
2-
import scala.quoted.Liftable._
32

43
object Test {
54

tests/pos/quote-liftable.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import scala.quoted._
22

3-
import scala.quoted.Liftable._
4-
53
object Test {
64

75
implicit def IntIsLiftable: Liftable[Int] = new {

tests/run-with-compiler/i4044b.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import scala.quoted._
2-
import scala.quoted.Liftable._
32

43
import dotty.tools.dotc.quoted.Toolbox._
54

tests/run-with-compiler/quote-lib.scala

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
import scala.quoted._
3-
import scala.quoted.Liftable._
43
import dotty.tools.dotc.quoted.Toolbox._
54

65
import liftable.Units._
@@ -43,7 +42,6 @@ object Test {
4342

4443
package liftable {
4544
import scala.quoted.Liftable
46-
import scala.quoted.Liftable._
4745
import scala.reflect.ClassTag
4846

4947
object Exprs {

tests/run-with-compiler/quote-run-constants-extract-1.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import scala.quoted._
2-
import scala.quoted.Liftable._
32

43
import dotty.tools.dotc.quoted.Toolbox._
54

tests/run-with-compiler/quote-run-constants-extract-2.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import scala.quoted._
2-
import scala.quoted.Liftable._
32

43
import dotty.tools.dotc.quoted.Toolbox._
54

tests/run-with-compiler/quote-run-constants-extract-3.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import scala.quoted._
2-
import scala.quoted.Liftable._
32

43
import dotty.tools.dotc.quoted.Toolbox._
54

tests/run-with-compiler/quote-run-constants-extract-4.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import scala.quoted._
2-
import scala.quoted.Liftable._
32

43
import dotty.tools.dotc.quoted.Toolbox._
54

tests/run-with-compiler/quote-run-constants-extract-5.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import scala.quoted._
2-
import scala.quoted.Liftable._
32

43
import dotty.tools.dotc.quoted.Toolbox._
54

tests/run-with-compiler/quote-run-constants-extract-6.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import scala.quoted._
2-
import scala.quoted.Liftable._
32

43
import dotty.tools.dotc.quoted.Toolbox._
54

tests/run-with-compiler/quote-run-constants.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import dotty.tools.dotc.quoted.Toolbox._
33

44
import scala.quoted._
5-
import scala.quoted.Liftable._
65

76
object Test {
87
def main(args: Array[String]): Unit = {

tests/run-with-compiler/quote-run-staged-interpreter.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import scala.quoted._
2-
import scala.quoted.Liftable._
32

43
import dotty.tools.dotc.quoted.Toolbox._
54

tests/run-with-compiler/quote-show-blocks-raw.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import dotty.tools.dotc.quoted.Toolbox._
33

44
import scala.quoted._
5-
import scala.quoted.Liftable._
65

76
object Test {
87
def main(args: Array[String]): Unit = {

tests/run-with-compiler/quote-show-blocks.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
import dotty.tools.dotc.quoted.Toolbox._
33

44
import scala.quoted._
5-
import scala.quoted.Liftable._
65

76
object Test {
87
def main(args: Array[String]): Unit = {

tests/run/quote-splice-interpret-1/Macro_1.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import dotty.tools.dotc.ast.Trees.Import
22

33
import scala.quoted._
4-
import scala.quoted.Liftable._
54

65
object Macros {
76
sealed trait Nat

0 commit comments

Comments
 (0)