File tree Expand file tree Collapse file tree 5 files changed +34
-62
lines changed
pos-macros/quote-lift-inline-params Expand file tree Collapse file tree 5 files changed +34
-62
lines changed Original file line number Diff line number Diff line change
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
+ }
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
import scala .quoted .Expr
2
2
object Macro {
3
- import quoted .Liftable .{IntIsLiftable => _ }
4
3
inline def foo (inline n : Int ): Int = $ {
5
4
' n
6
5
}
Original file line number Diff line number Diff line change 1
1
import scala .quoted .Expr
2
- import quoted .Liftable .{IntIsLiftable => _ }
3
2
object Macro {
4
3
inline def foo (inline n : Int ): Int = $ {
5
4
' n
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ object Test {
7
7
{
8
8
import Liftable ._
9
9
10
- ' { $ {IntIsLiftable .toExpr(1 )} }
10
+ ' { $ {the[ Liftable [ Int ]] .toExpr(1 )} }
11
11
12
12
' { $ {1 .toExpr} }
13
13
You can’t perform that action at this time.
0 commit comments