Skip to content

Commit fada008

Browse files
committed
Change ConstantExpr to ValueExpr and add documentation
1 parent b7119e7 commit fada008

File tree

4 files changed

+19
-17
lines changed

4 files changed

+19
-17
lines changed

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ object PickledQuotes {
3737
/** Transform the expression into its fully spliced Tree */
3838
def quotedExprToTree(expr: quoted.Expr[_])(implicit ctx: Context): Tree = expr match {
3939
case expr: TastyExpr[_] => unpickleExpr(expr)
40-
case expr: ConstantExpr[_] => Literal(Constant(expr.value))
40+
case expr: ValueExpr[_] => Literal(Constant(expr.value))
4141
case expr: RawExpr[Tree] @unchecked => expr.tree
4242
case expr: FunctionAppliedTo[_, _] =>
4343
functionAppliedTo(quotedExprToTree(expr.f), quotedExprToTree(expr.x))

compiler/src/dotty/tools/dotc/quoted/Runners.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import dotty.tools.dotc.core.Contexts._
77
import dotty.tools.dotc.printing.RefinedPrinter
88

99
import scala.quoted.Expr
10-
import scala.quoted.Exprs.ConstantExpr
10+
import scala.quoted.Exprs.ValueExpr
1111
import scala.runtime.quoted._
1212

1313
/** Default runners for quoted expressions */
@@ -19,7 +19,7 @@ object Runners {
1919
def run(expr: Expr[T]): T = Runners.run(expr, RunSettings())
2020

2121
def show(expr: Expr[T]): String = expr match {
22-
case expr: ConstantExpr[T] =>
22+
case expr: ValueExpr[T] =>
2323
implicit val ctx = new QuoteDriver().initCtx
2424
ctx.settings.color.update("never")
2525
val printer = new RefinedPrinter(ctx)
@@ -35,15 +35,15 @@ object Runners {
3535
case _ => None
3636
}
3737
expr match {
38-
case expr: ConstantExpr[T] => Some(expr.value)
38+
case expr: ValueExpr[T] => Some(expr.value)
3939
case _ => new QuoteDriver().withTree(expr, (tree, _) => toConstantOpt(tree))
4040
}
4141
}
4242

4343
}
4444

4545
def run[T](expr: Expr[T], settings: RunSettings): T = expr match {
46-
case expr: ConstantExpr[T] => expr.value
46+
case expr: ValueExpr[T] => expr.value
4747
case _ => new QuoteDriver().run(expr, settings)
4848
}
4949

library/src/scala/quoted/Expr.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ object Exprs {
2626
override def toString(): String = s"Expr(<pickled>)"
2727
}
2828

29-
/** An Expr backed by a value */
30-
final class ConstantExpr[T](val value: T) extends Expr[T] {
29+
/** An Expr backed by a value.
30+
* Values can only be of type Boolean, Byte, Short, Char, Int, Long, Float, Double, Unit, String or Null.
31+
*/
32+
final class ValueExpr[T](val value: T) extends Expr[T] {
3133
override def toString: String = s"Expr($value)"
3234
}
3335

library/src/scala/quoted/Liftable.scala

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package scala.quoted
22

3-
import scala.quoted.Exprs.ConstantExpr
3+
import scala.quoted.Exprs.ValueExpr
44

55
/** A typeclass for types that can be turned to `quoted.Expr[T]`
66
* without going through an explicit `'(...)` operation.
@@ -20,14 +20,14 @@ object Liftable {
2020
def toExpr(implicit liftable: Liftable[T]): Expr[T] = liftable.toExpr(x)
2121
}
2222

23-
implicit def BooleanIsLiftable: Liftable[Boolean] = (x: Boolean) => new ConstantExpr(x)
24-
implicit def ByteLiftable: Liftable[Byte] = (x: Byte) => new ConstantExpr(x)
25-
implicit def CharIsLiftable: Liftable[Char] = (x: Char) => new ConstantExpr(x)
26-
implicit def ShortIsLiftable: Liftable[Short] = (x: Short) => new ConstantExpr(x)
27-
implicit def IntIsLiftable: Liftable[Int] = (x: Int) => new ConstantExpr(x)
28-
implicit def LongIsLiftable: Liftable[Long] = (x: Long) => new ConstantExpr(x)
29-
implicit def FloatIsLiftable: Liftable[Float] = (x: Float) => new ConstantExpr(x)
30-
implicit def DoubleIsLiftable: Liftable[Double] = (x: Double) => new ConstantExpr(x)
23+
implicit def BooleanIsLiftable: Liftable[Boolean] = (x: Boolean) => new ValueExpr(x)
24+
implicit def ByteLiftable: Liftable[Byte] = (x: Byte) => new ValueExpr(x)
25+
implicit def CharIsLiftable: Liftable[Char] = (x: Char) => new ValueExpr(x)
26+
implicit def ShortIsLiftable: Liftable[Short] = (x: Short) => new ValueExpr(x)
27+
implicit def IntIsLiftable: Liftable[Int] = (x: Int) => new ValueExpr(x)
28+
implicit def LongIsLiftable: Liftable[Long] = (x: Long) => new ValueExpr(x)
29+
implicit def FloatIsLiftable: Liftable[Float] = (x: Float) => new ValueExpr(x)
30+
implicit def DoubleIsLiftable: Liftable[Double] = (x: Double) => new ValueExpr(x)
3131

32-
implicit def StringIsLiftable: Liftable[String] = (x: String) => new ConstantExpr(x)
32+
implicit def StringIsLiftable: Liftable[String] = (x: String) => new ValueExpr(x)
3333
}

0 commit comments

Comments
 (0)