Skip to content

Commit 143444e

Browse files
Merge pull request #6480 from dotty-staging/bootstrap-quoted-liftable
Use Dotty features in quoted.Liftable
2 parents abb4059 + 69f83cb commit 143444e

File tree

5 files changed

+34
-62
lines changed

5 files changed

+34
-62
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package scala.quoted
2+
3+
import scala.runtime.quoted.Unpickler.liftedExpr
4+
5+
/** A typeclass for types that can be turned to `quoted.Expr[T]`
6+
* without going through an explicit `'{...}` operation.
7+
*/
8+
abstract class Liftable[T] {
9+
def toExpr(x: T): Expr[T]
10+
}
11+
12+
/** Some liftable base types. To be completed with at least all types
13+
* that are valid Scala literals. The actual implementation of these
14+
* typed could be in terms of `ast.tpd.Literal`; the test `quotable.scala`
15+
* gives an alternative implementation using just the basic staging system.
16+
*/
17+
object Liftable {
18+
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)
31+
}
32+
33+
}

library/src/scala/quoted/Liftable.scala

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

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)