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 11import scala .quoted .Expr
22object Macro {
3- import quoted .Liftable .{IntIsLiftable => _ }
43 inline def foo (inline n : Int ): Int = $ {
54 ' n
65 }
Original file line number Diff line number Diff line change 11import scala .quoted .Expr
2- import quoted .Liftable .{IntIsLiftable => _ }
32object Macro {
43 inline def foo (inline n : Int ): Int = $ {
54 ' n
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments