@@ -206,25 +206,23 @@ class ReifyQuotes extends MacroTransform {
206
206
qctx
207
207
}
208
208
209
- def liftedValue [T ](value : T , name : TermName ) =
210
- ref(defn.LiftableModule )
211
- .select(name).appliedToType(originalTp)
212
- .select(" toExpr" .toTermName).appliedTo(Literal (Constant (value)))
213
-
214
- def pickleAsValue [T ](value : T ) =
215
- value match {
216
- case null => ref(defn.QuotedExprModule ).select(" nullExpr" .toTermName)
217
- case _ : Unit => ref(defn.QuotedExprModule ).select(" unitExpr" .toTermName)
218
- case _ : Boolean => liftedValue(value, " Liftable_Boolean_delegate" .toTermName)
219
- case _ : Byte => liftedValue(value, " Liftable_Byte_delegate" .toTermName)
220
- case _ : Short => liftedValue(value, " Liftable_Short_delegate" .toTermName)
221
- case _ : Int => liftedValue(value, " Liftable_Int_delegate" .toTermName)
222
- case _ : Long => liftedValue(value, " Liftable_Long_delegate" .toTermName)
223
- case _ : Float => liftedValue(value, " Liftable_Float_delegate" .toTermName)
224
- case _ : Double => liftedValue(value, " Liftable_Double_delegate" .toTermName)
225
- case _ : Char => liftedValue(value, " Liftable_Char_delegate" .toTermName)
226
- case _ : String => liftedValue(value, " Liftable_String_delegate" .toTermName)
209
+ def pickleAsLiteral (lit : Literal ) = {
210
+ def liftedValue (lifter : Symbol ) =
211
+ ref(lifter).appliedToType(originalTp).select(nme.toExpr).appliedTo(lit)
212
+ lit.const.tag match {
213
+ case Constants .NullTag => ref(defn.QuotedExprModule_nullExpr )
214
+ case Constants .UnitTag => ref(defn.QuotedExprModule_unitExpr )
215
+ case Constants .BooleanTag => liftedValue(defn.LiftableModule_BooleanIsLiftable )
216
+ case Constants .ByteTag => liftedValue(defn.LiftableModule_ByteIsLiftable )
217
+ case Constants .ShortTag => liftedValue(defn.LiftableModule_ShortIsLiftable )
218
+ case Constants .IntTag => liftedValue(defn.LiftableModule_IntIsLiftable )
219
+ case Constants .LongTag => liftedValue(defn.LiftableModule_LongIsLiftable )
220
+ case Constants .FloatTag => liftedValue(defn.LiftableModule_FloatIsLiftable )
221
+ case Constants .DoubleTag => liftedValue(defn.LiftableModule_DoubleIsLiftable )
222
+ case Constants .CharTag => liftedValue(defn.LiftableModule_CharIsLiftable )
223
+ case Constants .StringTag => liftedValue(defn.LiftableModule_StringIsLiftable )
227
224
}
225
+ }
228
226
229
227
def pickleAsTasty () = {
230
228
val meth =
@@ -243,8 +241,8 @@ class ReifyQuotes extends MacroTransform {
243
241
if (splices.isEmpty && body.symbol.isPrimitiveValueClass) tag(s " ${body.symbol.name}Tag " )
244
242
else pickleAsTasty().select(nme.apply).appliedTo(qctx)
245
243
}
246
- else toValue (body) match {
247
- case Some (value ) => pickleAsValue(value )
244
+ else getLiteral (body) match {
245
+ case Some (lit ) => pickleAsLiteral(lit )
248
246
case _ => pickleAsTasty()
249
247
}
250
248
}
@@ -429,10 +427,10 @@ object ReifyQuotes {
429
427
430
428
val name : String = " reifyQuotes"
431
429
432
- def toValue (tree : tpd.Tree ): Option [Any ] = tree match {
433
- case Literal ( Constant (c)) => Some (c )
434
- case Block (Nil , e) => toValue (e)
435
- case Inlined (_, Nil , e) => toValue (e)
430
+ def getLiteral (tree : tpd.Tree ): Option [Literal ] = tree match {
431
+ case tree : Literal => Some (tree )
432
+ case Block (Nil , e) => getLiteral (e)
433
+ case Inlined (_, Nil , e) => getLiteral (e)
436
434
case _ => None
437
435
}
438
436
0 commit comments