Skip to content

Commit eeb58bd

Browse files
committed
Add String to Liftable expressions and abstract over all primitives
1 parent aa0f03e commit eeb58bd

File tree

4 files changed

+13
-4
lines changed

4 files changed

+13
-4
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ object PickledQuotes {
2727
/** Transform the expression into it's fully spliced Tree */
2828
def quotedToTree(expr: quoted.Quoted)(implicit ctx: Context): Tree = expr match {
2929
case expr: quoted.TastyQuoted => unpickleQuote(expr)
30-
case expr: quoted.ValueExpr[_] => Literal(Constant(expr.value))
30+
case expr: quoted.Liftable.PrimitiveExpr[_] => Literal(Constant(expr.value))
3131
case expr: RawQuoted => expr.tree
3232
}
3333

library/src/scala/quoted/Liftable.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ abstract class Liftable[T] {
1313
* gives an alternative implementation using just the basic staging system.
1414
*/
1515
object Liftable {
16+
17+
sealed abstract class PrimitiveExpr[T] extends Expr[T] {
18+
def value: T
19+
}
20+
21+
private class ValueExpr[T <: AnyVal](val value: T) extends PrimitiveExpr[T]
22+
1623
implicit def BooleanIsLiftable: Liftable[Boolean] = (x: Boolean) => new ValueExpr(x)
1724
implicit def ByteLiftable: Liftable[Byte] = (x: Byte) => new ValueExpr(x)
1825
implicit def CharIsLiftable: Liftable[Char] = (x: Char) => new ValueExpr(x)
@@ -21,4 +28,8 @@ object Liftable {
2128
implicit def LongIsLiftable: Liftable[Long] = (x: Long) => new ValueExpr(x)
2229
implicit def FloatIsLiftable: Liftable[Float] = (x: Float) => new ValueExpr(x)
2330
implicit def DoubleIsLiftable: Liftable[Double] = (x: Double) => new ValueExpr(x)
31+
32+
private class StringExpr(val value: String) extends PrimitiveExpr[String]
33+
34+
implicit def StringIsLiftable: Liftable[String] = (x: String) => new StringExpr(x)
2435
}

library/src/scala/quoted/ValueExpr.scala

Lines changed: 0 additions & 3 deletions
This file was deleted.

tests/pos/quote-liftable.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ object Test {
3232
(1L: Expr[Long])
3333
(1.0f: Expr[Float])
3434
(1.0: Expr[Double])
35+
("abc": Expr[String])
3536

3637
val xs: Expr[List[Int]] = 1 :: 2 :: 3 :: Nil
3738
}

0 commit comments

Comments
 (0)