Skip to content

Commit 09bb61f

Browse files
committed
Change ConstantExpr to ValueExpr and add documentation
1 parent 3e9330f commit 09bb61f

File tree

4 files changed

+20
-18
lines changed

4 files changed

+20
-18
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
@@ -33,7 +33,7 @@ object PickledQuotes {
3333
/** Transform the expression into its fully spliced Tree */
3434
def quotedExprToTree(expr: quoted.Expr[_])(implicit ctx: Context): Tree = expr match {
3535
case expr: TastyExpr[_] => unpickleExpr(expr)
36-
case expr: ConstantExpr[_] => Literal(Constant(expr.value))
36+
case expr: ValueExpr[_] => Literal(Constant(expr.value))
3737
case expr: RawExpr[Tree] @unchecked => expr.tree
3838
case expr: FunctionAppliedTo[_, _] =>
3939
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.printing.RefinedPrinter
77

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

1313
/** Default runners for quoted expressions */
@@ -31,20 +31,20 @@ object Runners {
3131
case _ => None
3232
}
3333
expr match {
34-
case expr: ConstantExpr[T] => Some(expr.value)
34+
case expr: ValueExpr[T] => Some(expr.value)
3535
case _ => new QuoteDriver().withTree(expr, (tree, _) => toConstantOpt(tree), Settings.run())
3636
}
3737
}
3838

3939
}
4040

4141
def run[T](expr: Expr[T], settings: Settings[Run]): T = expr match {
42-
case expr: ConstantExpr[T] => expr.value
42+
case expr: ValueExpr[T] => expr.value
4343
case _ => new QuoteDriver().run(expr, settings)
4444
}
4545

4646
def show[T](expr: Expr[T], settings: Settings[Show]): String = expr match {
47-
case expr: ConstantExpr[T] =>
47+
case expr: ValueExpr[T] =>
4848
implicit val ctx = new QuoteDriver().initCtx
4949
if (settings.compilerArgs.contains("-color:never"))
5050
ctx.settings.color.update("never")

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: 11 additions & 11 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,15 +20,15 @@ object Liftable {
2020
def toExpr(implicit liftable: Liftable[T]): Expr[T] = liftable.toExpr(x)
2121
}
2222

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

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

0 commit comments

Comments
 (0)