@@ -190,13 +190,30 @@ class ReifyQuotes extends MacroTransform {
190
190
}
191
191
}
192
192
193
+ /** Encode quote using QuoteContextInternal.{unpickleExpr, unpickleType}
194
+ *
195
+ * Generate the code
196
+ * ```scala
197
+ * qctx => qctx.asInstanceOf[QuoteContextInternal].<unpickleExpr|unpickleType>(
198
+ * <pickledQuote>
199
+ * ).asInstanceOf[scala.quoted.<Expr|Type>[<type>]]
200
+ * ```
201
+ * this closure is always applied directly to the actual context and the BetaReduce phase removes it.
202
+ */
193
203
def pickleAsTasty () = {
194
- val unpickleMeth = if isType then defn.PickledQuote_unpickleType else defn.PickledQuote_unpickleExpr
195
204
val pickledQuoteStrings = liftList(PickledQuotes .pickleQuote(body).map(x => Literal (Constant (x))), defn.StringType )
196
205
// TODO: generate an instance of PickledSplices directly instead of passing through a List
197
206
val splicesList = liftList(splices, defn.FunctionType (1 ).appliedTo(defn.SeqType .appliedTo(defn.AnyType ), defn.AnyType ))
198
207
val pickledQuote = ref(defn.PickledQuote_make ).appliedTo(pickledQuoteStrings, splicesList)
199
- ref(unpickleMeth).appliedToType(originalTp).appliedTo(pickledQuote)
208
+ val quoteClass = if isType then defn.QuotedTypeClass else defn.QuotedExprClass
209
+ val quotedType = quoteClass.typeRef.appliedTo(originalTp)
210
+ val lambdaTpe = MethodType (defn.QuoteContextClass .typeRef :: Nil , quotedType)
211
+ def callUnpickle (ts : List [Tree ]) = {
212
+ val qctx = ts.head.asInstance(defn.QuoteContextInternalClass .typeRef)
213
+ val unpickleMethName = if isType then " unpickleType" else " unpickleExpr"
214
+ qctx.select(unpickleMethName.toTermName).appliedTo(pickledQuote).asInstance(quotedType)
215
+ }
216
+ Lambda (lambdaTpe, callUnpickle).withSpan(body.span)
200
217
}
201
218
202
219
/** Encode quote using Reflection.TypeRepr.typeConstructorOf
0 commit comments