@@ -206,19 +206,16 @@ class ReifyQuotes extends MacroTransform {
206
206
qctx
207
207
}
208
208
209
- def liftedValue [T ](const : Constant ) = {
210
- val ltp = defn.LiftableClass .typeRef.appliedTo(ConstantType (const))
211
- val liftable = ctx.typer.inferImplicitArg(ltp, body.span)
212
- if (liftable.tpe.isInstanceOf [SearchFailureType ])
213
- ctx.error(ctx.typer.missingArgMsg(liftable, ltp, " Could no optimize constant in quote" ), ctx.source.atSpan(body.span))
214
- liftable.select(" toExpr" .toTermName).appliedTo(Literal (const))
215
- }
216
-
217
- def pickleAsValue [T ](value : T ) =
218
- value match {
219
- case null => ref(defn.QuotedExprModule ).select(" nullExpr" .toTermName)
220
- case _ : Unit => ref(defn.QuotedExprModule ).select(" unitExpr" .toTermName)
221
- case _ => liftedValue(Constant (value))
209
+ def pickleAsLiteral (lit : Literal ) =
210
+ lit.const.tag match {
211
+ case Constants .NullTag => ref(defn.QuotedExprModule ).select(" nullExpr" .toTermName)
212
+ case Constants .UnitTag => ref(defn.QuotedExprModule ).select(" unitExpr" .toTermName)
213
+ case _ => // Lifted literal
214
+ val ltp = defn.LiftableClass .typeRef.appliedTo(ConstantType (lit.const))
215
+ val liftable = ctx.typer.inferImplicitArg(ltp, body.span)
216
+ if (liftable.tpe.isInstanceOf [SearchFailureType ])
217
+ ctx.error(ctx.typer.missingArgMsg(liftable, ltp, " Could no optimize constant in quote" ), ctx.source.atSpan(body.span))
218
+ liftable.select(" toExpr" .toTermName).appliedTo(lit)
222
219
}
223
220
224
221
def pickleAsTasty () = {
@@ -238,8 +235,8 @@ class ReifyQuotes extends MacroTransform {
238
235
if (splices.isEmpty && body.symbol.isPrimitiveValueClass) tag(s " ${body.symbol.name}Tag " )
239
236
else pickleAsTasty().select(nme.apply).appliedTo(qctx)
240
237
}
241
- else toValue (body) match {
242
- case Some (value ) => pickleAsValue(value )
238
+ else getLiteral (body) match {
239
+ case Some (lit ) => pickleAsLiteral(lit )
243
240
case _ => pickleAsTasty()
244
241
}
245
242
}
@@ -424,10 +421,10 @@ object ReifyQuotes {
424
421
425
422
val name : String = " reifyQuotes"
426
423
427
- def toValue (tree : tpd.Tree ): Option [Any ] = tree match {
428
- case Literal ( Constant (c)) => Some (c )
429
- case Block (Nil , e) => toValue (e)
430
- case Inlined (_, Nil , e) => toValue (e)
424
+ def getLiteral (tree : tpd.Tree ): Option [Literal ] = tree match {
425
+ case tree : Literal => Some (tree )
426
+ case Block (Nil , e) => getLiteral (e)
427
+ case Inlined (_, Nil , e) => getLiteral (e)
431
428
case _ => None
432
429
}
433
430
0 commit comments