Skip to content

Commit 0fb7f4a

Browse files
Merge pull request #3910 from dotty-staging/use-lists-for-quote-args
Use List for quote arguments as is done with quote pickled strings
2 parents 1f51376 + dba7f20 commit 0fb7f4a

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

compiler/src/dotty/tools/dotc/core/quoted/PickledQuotes.scala

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,12 @@ object PickledQuotes {
1919
import tpd._
2020

2121
/** Pickle the quote into strings */
22-
def pickleQuote(tree: Tree)(implicit ctx: Context): Tree = {
23-
if (ctx.reporter.hasErrors) Literal(Constant("<error>"))
22+
def pickleQuote(tree: Tree)(implicit ctx: Context): scala.runtime.quoted.Unpickler.Pickled = {
23+
if (ctx.reporter.hasErrors) Nil
2424
else {
2525
val encapsulated = encapsulateQuote(tree)
2626
val pickled = pickle(encapsulated)
27-
TastyString.pickle(pickled).foldRight[Tree](ref(defn.NilModule)) { (x, acc) =>
28-
acc.select("::".toTermName)
29-
.appliedToType(defn.StringType)
30-
.appliedTo(Literal(Constant(x)))
31-
}
27+
TastyString.pickle(pickled)
3228
}
3329
}
3430

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,17 @@ class ReifyQuotes extends MacroTransform {
265265
if (inSplice)
266266
makeHole(body1, splices, quote.tpe)
267267
else {
268+
def liftList(list: List[Tree], tpe: Type): Tree = {
269+
list.foldRight[Tree](ref(defn.NilModule)) { (x, acc) =>
270+
acc.select("::".toTermName).appliedToType(tpe).appliedTo(x)
271+
}
272+
}
268273
val isType = quote.tpe.isRef(defn.QuotedTypeClass)
269274
ref(if (isType) defn.Unpickler_unpickleType else defn.Unpickler_unpickleExpr)
270275
.appliedToType(if (isType) body1.tpe else body1.tpe.widen)
271276
.appliedTo(
272-
PickledQuotes.pickleQuote(body1),
273-
SeqLiteral(splices, TypeTree(defn.AnyType)))
277+
liftList(PickledQuotes.pickleQuote(body1).map(x => Literal(Constant(x))), defn.StringType),
278+
liftList(splices, defn.AnyType))
274279
}
275280
}.withPos(quote.pos)
276281

0 commit comments

Comments
 (0)