File tree Expand file tree Collapse file tree 4 files changed +48
-1
lines changed
compiler/src/dotty/tools/dotc Expand file tree Collapse file tree 4 files changed +48
-1
lines changed Original file line number Diff line number Diff line change @@ -121,13 +121,14 @@ object PickledQuotes {
121121 private def classTagToTypeTree (ct : ClassTag [_])(implicit ctx : Context ): TypeTree = {
122122 val tpe = ct match {
123123 case ClassTag .Unit => defn.UnitType
124+ case ClassTag .Boolean => defn.BooleanType
124125 case ClassTag .Byte => defn.ByteType
125126 case ClassTag .Char => defn.CharType
126127 case ClassTag .Short => defn.ShortType
127128 case ClassTag .Int => defn.IntType
128129 case ClassTag .Long => defn.LongType
129130 case ClassTag .Float => defn.FloatType
130- case ClassTag .Double => defn.FloatType
131+ case ClassTag .Double => defn.DoubleType
131132 }
132133 TypeTree (tpe)
133134 }
Original file line number Diff line number Diff line change @@ -352,6 +352,19 @@ class ReifyQuotes extends MacroTransformWithImplicits {
352352 liftList(splices, defn.AnyType ))
353353 }
354354 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+ }
355368 else ReifyQuotes .toValue(body) match {
356369 case Some (value) => pickleAsValue(value)
357370 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