Skip to content

Commit ac2c44a

Browse files
committed
Use implied instances for primitive liftables
1 parent 7214dd2 commit ac2c44a

File tree

4 files changed

+13
-41
lines changed

4 files changed

+13
-41
lines changed

library/src-3.x/scala/quoted/Liftable.scala

Lines changed: 12 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,44 +16,18 @@ abstract class Liftable[T] {
1616
*/
1717
object Liftable {
1818

19-
implicit def BooleanIsLiftable: Liftable[Boolean] = new Liftable[Boolean] {
20-
def toExpr(x: Boolean): Expr[Boolean] = liftedExpr(x)
21-
}
22-
23-
implicit def ByteIsLiftable: Liftable[Byte] = new Liftable[Byte] {
24-
def toExpr(x: Byte): Expr[Byte] = liftedExpr(x)
25-
}
26-
27-
implicit def CharIsLiftable: Liftable[Char] = new Liftable[Char] {
28-
def toExpr(x: Char): Expr[Char] = liftedExpr(x)
29-
}
30-
31-
implicit def ShortIsLiftable: Liftable[Short] = new Liftable[Short] {
32-
def toExpr(x: Short): Expr[Short] = liftedExpr(x)
33-
}
34-
35-
implicit def IntIsLiftable: Liftable[Int] = new Liftable[Int] {
36-
def toExpr(x: Int): Expr[Int] = liftedExpr(x)
37-
}
38-
39-
implicit def LongIsLiftable: Liftable[Long] = new Liftable[Long] {
40-
def toExpr(x: Long): Expr[Long] = liftedExpr(x)
41-
}
42-
43-
implicit def FloatIsLiftable: Liftable[Float] = new Liftable[Float] {
44-
def toExpr(x: Float): Expr[Float] = liftedExpr(x)
45-
}
46-
47-
implicit def DoubleIsLiftable: Liftable[Double] = new Liftable[Double] {
48-
def toExpr(x: Double): Expr[Double] = liftedExpr(x)
49-
}
50-
51-
implicit def StringIsLiftable: Liftable[String] = new Liftable[String] {
52-
def toExpr(x: String): Expr[String] = liftedExpr(x)
53-
}
54-
55-
implicit def ClassIsLiftable[T]: Liftable[Class[T]] = new Liftable[Class[T]] {
56-
def toExpr(x: Class[T]): Expr[Class[T]] = liftedExpr(x)
19+
implied for Liftable[Boolean] = new PrimitiveLifable
20+
implied for Liftable[Short] = new PrimitiveLifable
21+
implied for Liftable[Int] = new PrimitiveLifable
22+
implied for Liftable[Long] = new PrimitiveLifable
23+
implied for Liftable[Float] = new PrimitiveLifable
24+
implied for Liftable[Double] = new PrimitiveLifable
25+
implied for Liftable[Char] = new PrimitiveLifable
26+
implied for Liftable[String] = new PrimitiveLifable
27+
implied ClassIsLiftable[T] for Liftable[Class[T]] = new PrimitiveLifable // FIXME: annonymous implied with type parameter not working
28+
29+
private class PrimitiveLifable[T] extends Liftable[T] {
30+
override def toExpr(x: T): Expr[T] = liftedExpr(x)
5731
}
5832

5933
}

tests/pos-macros/quote-lift-inline-params/Macro_1.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import scala.quoted.Expr
22
object Macro {
3-
import quoted.Liftable.{IntIsLiftable => _}
43
inline def foo(inline n: Int): Int = ${
54
'n
65
}

tests/pos/quote-lift-inline-params-b.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import scala.quoted.Expr
2-
import quoted.Liftable.{IntIsLiftable => _}
32
object Macro {
43
inline def foo(inline n: Int): Int = ${
54
'n

tests/pos/quote-lift.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ object Test {
77
{
88
import Liftable._
99

10-
'{ ${IntIsLiftable.toExpr(1)} }
10+
'{ ${the[Liftable[Int]].toExpr(1)} }
1111

1212
'{ ${1.toExpr} }
1313

0 commit comments

Comments
 (0)