File tree 4 files changed +42
-2
lines changed
compiler/src/dotty/tools/dotc/core/quoted
4 files changed +42
-2
lines changed Original file line number Diff line number Diff line change @@ -12,6 +12,8 @@ import dotty.tools.dotc.core.Symbols._
12
12
import dotty .tools .dotc .core .tasty .{TastyPickler , TastyPrinter , TastyString }
13
13
import dotty .tools .dotc .interpreter .RawQuoted
14
14
15
+ import scala .reflect .ClassTag
16
+
15
17
object PickledQuotes {
16
18
import tpd ._
17
19
@@ -33,6 +35,18 @@ object PickledQuotes {
33
35
def quotedToTree (expr : quoted.Quoted )(implicit ctx : Context ): Tree = expr match {
34
36
case expr : quoted.TastyQuoted => unpickleQuote(expr)
35
37
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)
36
50
case expr : RawQuoted => expr.tree
37
51
}
38
52
Original file line number Diff line number Diff line change 1
1
package scala .quoted
2
2
3
+ import scala .reflect .ClassTag
4
+
3
5
class Type [T ] extends Quoted {
4
6
type unary_~ = T
5
7
}
6
8
7
9
/** Some basic type tags, currently incomplete */
8
10
object 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 ]
11
23
}
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