File tree 4 files changed +48
-1
lines changed
compiler/src/dotty/tools/dotc
4 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -121,13 +121,14 @@ object PickledQuotes {
121
121
private def classTagToTypeTree (ct : ClassTag [_])(implicit ctx : Context ): TypeTree = {
122
122
val tpe = ct match {
123
123
case ClassTag .Unit => defn.UnitType
124
+ case ClassTag .Boolean => defn.BooleanType
124
125
case ClassTag .Byte => defn.ByteType
125
126
case ClassTag .Char => defn.CharType
126
127
case ClassTag .Short => defn.ShortType
127
128
case ClassTag .Int => defn.IntType
128
129
case ClassTag .Long => defn.LongType
129
130
case ClassTag .Float => defn.FloatType
130
- case ClassTag .Double => defn.FloatType
131
+ case ClassTag .Double => defn.DoubleType
131
132
}
132
133
TypeTree (tpe)
133
134
}
Original file line number Diff line number Diff line change @@ -352,6 +352,19 @@ class ReifyQuotes extends MacroTransformWithImplicits {
352
352
liftList(splices, defn.AnyType ))
353
353
}
354
354
if (splices.nonEmpty) pickleAsTasty()
355
+ else if (isType) {
356
+ def tag (tagName : String ) = ref(defn.QuotedTypeModule ).select(tagName.toTermName)
357
+ if (body.symbol == defn.UnitClass ) tag(" UnitTag" )
358
+ else if (body.symbol == defn.BooleanClass ) tag(" BooleanTag" )
359
+ else if (body.symbol == defn.ByteClass ) tag(" ByteTag" )
360
+ else if (body.symbol == defn.CharClass ) tag(" CharTag" )
361
+ else if (body.symbol == defn.ShortClass ) tag(" ShortTag" )
362
+ else if (body.symbol == defn.IntClass ) tag(" IntTag" )
363
+ else if (body.symbol == defn.LongClass ) tag(" LongTag" )
364
+ else if (body.symbol == defn.FloatClass ) tag(" FloatTag" )
365
+ else if (body.symbol == defn.DoubleClass ) tag(" DoubleTag" )
366
+ else pickleAsTasty()
367
+ }
355
368
else ReifyQuotes .toValue(body) match {
356
369
case Some (value) => pickleAsValue(value)
357
370
case _ => pickleAsTasty()
Original file line number Diff line number Diff line change
1
+ ().asInstanceOf[Unit]
2
+ true.asInstanceOf[Boolean]
3
+ 0.toByte.asInstanceOf[Byte]
4
+ 'a'.asInstanceOf[Char]
5
+ 1.toShort.asInstanceOf[Short]
6
+ 2.asInstanceOf[Int]
7
+ 3L.asInstanceOf[Long]
8
+ 4.0.asInstanceOf[Float]
9
+ 5.0.asInstanceOf[Double]
10
+ 5.0.asInstanceOf[Boolean]
Original file line number Diff line number Diff line change
1
+
2
+ import dotty .tools .dotc .quoted .Toolbox ._
3
+
4
+ import scala .quoted ._
5
+
6
+ object Test {
7
+ def main (args : Array [String ]): Unit = {
8
+ def asof [T , U ](x : Expr [T ], t : Type [U ]): Expr [U ] =
9
+ '((~x).asInstanceOf[~t])
10
+
11
+ println(asof('(), ' [Unit ]).show)
12
+ println(asof('(true), ' [Boolean ]).show)
13
+ println(asof('(0.toByte), ' [Byte ]).show)
14
+ println(asof('( ' a' ), ' [Char ]).show)
15
+ println(asof('(1.toShort), ' [Short ]).show)
16
+ println(asof('(2), ' [Int ]).show)
17
+ println(asof('(3L), ' [Long ]).show)
18
+ println(asof('(4f), ' [Float ]).show)
19
+ println(asof('(5d), ' [Double ]).show)
20
+
21
+ println(asof('(5d), ' [Boolean ]).show) // Will clearly fail at runtime but the code can be generated
22
+ }
23
+ }
You can’t perform that action at this time.
0 commit comments