@@ -104,9 +104,10 @@ class PickleQuotes extends MacroTransform {
104
104
val (contents, codeWithHoles) = makeHoles(quote.body)
105
105
val sourceRef = Inlines .inlineCallTrace(ctx.owner, tree.sourcePos)
106
106
val bodyWithHoles2 =
107
- if quote.body.isType then codeWithHoles
107
+ if quote.isTypeQuote then codeWithHoles
108
108
else Inlined (sourceRef, Nil , codeWithHoles)
109
- val pickled = PickleQuotes .pickle(quotes, bodyWithHoles2, contents, quote.bodyType)
109
+ val quote1 = cpy.Quote (quote)(body = bodyWithHoles2)
110
+ val pickled = PickleQuotes .pickle(quote1, quotes, contents)
110
111
transform(pickled) // pickle quotes that are in the contents
111
112
case tree : DefDef if ! tree.rhs.isEmpty && tree.symbol.isInlineMethod =>
112
113
// Shrink size of the tree. The methods have already been inlined.
@@ -202,7 +203,10 @@ object PickleQuotes {
202
203
val name : String = " pickleQuotes"
203
204
val description : String = " turn quoted trees into explicit run-time data structures"
204
205
205
- def pickle (quotes : Tree , body : Tree , contents : List [Tree ], originalTp : Type )(using Context ) = {
206
+ def pickle (quote : Quote , quotes : Tree , contents : List [Tree ])(using Context ) = {
207
+ val body = quote.body
208
+ val bodyType = quote.bodyType
209
+
206
210
/** Helper methods to construct trees calling methods in `Quotes.reflect` based on the current `quotes` tree */
207
211
object reflect extends ReifiedReflect {
208
212
val quotesTree = quotes
@@ -256,7 +260,7 @@ object PickleQuotes {
256
260
*/
257
261
def liftedValue (lit : Literal , lifter : Symbol ) =
258
262
val exprType = defn.QuotedExprClass .typeRef.appliedTo(body.tpe)
259
- ref(lifter).appliedToType(originalTp ).select(nme.apply).appliedTo(lit).appliedTo(quotes)
263
+ ref(lifter).appliedToType(bodyType ).select(nme.apply).appliedTo(lit).appliedTo(quotes)
260
264
261
265
def pickleAsValue (lit : Literal ) = {
262
266
// TODO should all constants be pickled as Literals?
@@ -334,18 +338,18 @@ object PickleQuotes {
334
338
case _ => Match (args(0 ).annotated(New (ref(defn.UncheckedAnnot .typeRef))), cases)
335
339
)
336
340
337
- val quoteClass = if body.isType then defn.QuotedTypeClass else defn.QuotedExprClass
338
- val quotedType = quoteClass.typeRef.appliedTo(originalTp )
341
+ val quoteClass = if quote.isTypeQuote then defn.QuotedTypeClass else defn.QuotedExprClass
342
+ val quotedType = quoteClass.typeRef.appliedTo(bodyType )
339
343
val lambdaTpe = MethodType (defn.QuotesClass .typeRef :: Nil , quotedType)
340
344
val unpickleMeth =
341
- if body.isType then defn.QuoteUnpickler_unpickleTypeV2
345
+ if quote.isTypeQuote then defn.QuoteUnpickler_unpickleTypeV2
342
346
else defn.QuoteUnpickler_unpickleExprV2
343
347
val unpickleArgs =
344
- if body.isType then List (pickledQuoteStrings, types)
348
+ if quote.isTypeQuote then List (pickledQuoteStrings, types)
345
349
else List (pickledQuoteStrings, types, termHoles)
346
350
quotes
347
351
.asInstance(defn.QuoteUnpicklerClass .typeRef)
348
- .select(unpickleMeth).appliedToType(originalTp )
352
+ .select(unpickleMeth).appliedToType(bodyType )
349
353
.appliedToArgs(unpickleArgs).withSpan(body.span)
350
354
}
351
355
0 commit comments