File tree Expand file tree Collapse file tree 4 files changed +43
-3
lines changed
compiler/src/dotty/tools/dotc/core/quoted Expand file tree Collapse file tree 4 files changed +43
-3
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ import dotty.tools.dotc.core.Symbols._
1212import dotty .tools .dotc .core .tasty .{TastyPickler , TastyPrinter , TastyString }
1313import dotty .tools .dotc .interpreter .RawQuoted
1414
15+ import scala .reflect .ClassTag
16+
1517object PickledQuotes {
1618 import tpd ._
1719
@@ -33,6 +35,18 @@ object PickledQuotes {
3335 def quotedToTree (expr : quoted.Quoted )(implicit ctx : Context ): Tree = expr match {
3436 case expr : quoted.TastyQuoted => unpickleQuote(expr)
3537 case expr : quoted.Liftable .ConstantExpr [_] => Literal (Constant (expr.value))
38+ case expr : quoted.Type .TaggedPrimitive [_] =>
39+ val tpe = expr.ct match {
40+ case ClassTag .Unit => defn.UnitType
41+ case ClassTag .Byte => defn.ByteType
42+ case ClassTag .Char => defn.CharType
43+ case ClassTag .Short => defn.ShortType
44+ case ClassTag .Int => defn.IntType
45+ case ClassTag .Long => defn.LongType
46+ case ClassTag .Float => defn.FloatType
47+ case ClassTag .Double => defn.FloatType
48+ }
49+ TypeTree (tpe)
3650 case expr : RawQuoted => expr.tree
3751 }
3852
Original file line number Diff line number Diff line change 11package scala .quoted
22
3- class Type [T ] extends Quoted {
3+ import scala .reflect .ClassTag
4+
5+ abstract class Type [T ] extends Quoted {
46 type unary_~ = T
57}
68
79/** Some basic type tags, currently incomplete */
810object Type {
9- implicit def IntTag : Type [Int ] = new Type [Int ]
10- implicit def BooleanTag : Type [Boolean ] = new Type [Boolean ]
11+
12+ class TaggedPrimitive [T ] private [Type ] (implicit val ct : ClassTag [T ]) extends Type [T ]
13+
14+ implicit def UnitTag : Type [Unit ] = new TaggedPrimitive [Unit ]
15+ implicit def BooleanTag : Type [Boolean ] = new TaggedPrimitive [Boolean ]
16+ implicit def ByteTag : Type [Byte ] = new TaggedPrimitive [Byte ]
17+ implicit def CharTag : Type [Char ] = new TaggedPrimitive [Char ]
18+ implicit def ShortTag : Type [Short ] = new TaggedPrimitive [Short ]
19+ implicit def IntTag : Type [Int ] = new TaggedPrimitive [Int ]
20+ implicit def LongTag : Type [Long ] = new TaggedPrimitive [Long ]
21+ implicit def FloatTag : Type [Float ] = new TaggedPrimitive [Float ]
22+ implicit def DoubleTag : Type [Double ] = new TaggedPrimitive [Double ]
1123}
Original file line number Diff line number Diff line change 1+ {
2+ val z: Int = 2
3+ ()
4+ }
Original file line number Diff line number Diff line change 1+ import dotty .tools .dotc .quoted .Runners ._
2+ import scala .quoted ._
3+ object Test {
4+ def main (args : Array [String ]): Unit = {
5+ def f [T ](x : Expr [T ])(t : Type [T ]) = ' {
6+ val z : t.unary_~ = ~ x
7+ }
8+ println(f('(2))(Type.IntTag).show)
9+ }
10+ }
You can’t perform that action at this time.
0 commit comments