@@ -10,6 +10,7 @@ import dotty.tools.dotc.core.Flags._
1010import dotty .tools .dotc .core .StdNames ._
1111import dotty .tools .dotc .core .NameKinds
1212import dotty .tools .dotc .core .Symbols ._
13+ import dotty .tools .dotc .core .Types .Type
1314import dotty .tools .dotc .core .tasty .{TastyPickler , TastyPrinter , TastyString }
1415
1516import scala .quoted .Types ._
@@ -31,9 +32,13 @@ object PickledQuotes {
3132 }
3233
3334 /** Transform the expression into its fully spliced Tree */
34- def quotedExprToTree (expr : quoted.Expr [_ ])(implicit ctx : Context ): Tree = expr match {
35+ def quotedExprToTree [ T ] (expr : quoted.Expr [T ])(implicit ctx : Context ): Tree = expr match {
3536 case expr : TastyExpr [_] => unpickleExpr(expr)
36- case expr : LiftedExpr [_] => Literal (Constant (expr.value))
37+ case expr : LiftedExpr [T ] =>
38+ expr.value match {
39+ case value : Class [_] => ref(defn.Predef_classOf ).appliedToType(classToType(value))
40+ case value=> Literal (Constant (value))
41+ }
3742 case expr : TreeExpr [Tree ] @ unchecked => expr.tree
3843 case expr : FunctionAppliedTo [_, _] =>
3944 functionAppliedTo(quotedExprToTree(expr.f), quotedExprToTree(expr.x))
@@ -154,4 +159,27 @@ object PickledQuotes {
154159 }
155160 Block (x1 :: Nil , rec(f))
156161 }
162+
163+ private def classToType (clazz : Class [_])(implicit ctx : Context ): Type = {
164+ if (clazz.isPrimitive) {
165+ if (clazz == classOf [Boolean ]) defn.BooleanType
166+ else if (clazz == classOf [Byte ]) defn.ByteType
167+ else if (clazz == classOf [Char ]) defn.CharType
168+ else if (clazz == classOf [Short ]) defn.ShortType
169+ else if (clazz == classOf [Int ]) defn.IntType
170+ else if (clazz == classOf [Long ]) defn.LongType
171+ else if (clazz == classOf [Float ]) defn.FloatType
172+ else if (clazz == classOf [Double ]) defn.DoubleType
173+ else defn.UnitType
174+ } else if (clazz.isArray) {
175+ defn.ArrayType .appliedTo(classToType(clazz.getComponentType))
176+ } else if (clazz.isMemberClass) {
177+ val name = clazz.getSimpleName.toTypeName
178+ val enclosing = classToType(clazz.getEnclosingClass)
179+ if (enclosing.member(name).exists) enclosing.select(name)
180+ else {
181+ enclosing.classSymbol.companionModule.termRef.select(name)
182+ }
183+ } else ctx.getClassIfDefined(clazz.getCanonicalName).typeRef
184+ }
157185}
0 commit comments