From 4c54db1200dc89db8040cbca59a227c90589a870 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 8 May 2018 13:25:11 +0200 Subject: [PATCH] Fix #4414: Use original type in generated unpickle{Expr|Type} --- .../src/dotty/tools/dotc/transform/ReifyQuotes.scala | 10 +++++----- tests/pos/i4414.scala | 11 +++++++++++ 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 tests/pos/i4414.scala diff --git a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala index 3751c1a4d4a7..e854231d1e05 100644 --- a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala @@ -386,17 +386,17 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer { } case _=> val (body1, splices) = nested(isQuote = true).split(body) - pickledQuote(body1, splices, isType).withPos(quote.pos) + pickledQuote(body1, splices, body.tpe, isType).withPos(quote.pos) } } - private def pickledQuote(body: Tree, splices: List[Tree], isType: Boolean)(implicit ctx: Context) = { + private def pickledQuote(body: Tree, splices: List[Tree], originalTp: Type, isType: Boolean)(implicit ctx: Context) = { def pickleAsValue[T](value: T) = - ref(defn.Unpickler_liftedExpr).appliedToType(body.tpe.widen).appliedTo(Literal(Constant(value))) + ref(defn.Unpickler_liftedExpr).appliedToType(originalTp.widen).appliedTo(Literal(Constant(value))) def pickleAsTasty() = { val meth = - if (isType) ref(defn.Unpickler_unpickleType).appliedToType(body.tpe) - else ref(defn.Unpickler_unpickleExpr).appliedToType(body.tpe.widen) + if (isType) ref(defn.Unpickler_unpickleType).appliedToType(originalTp) + else ref(defn.Unpickler_unpickleExpr).appliedToType(originalTp.widen) meth.appliedTo( liftList(PickledQuotes.pickleQuote(body).map(x => Literal(Constant(x))), defn.StringType), liftList(splices, defn.AnyType)) diff --git a/tests/pos/i4414.scala b/tests/pos/i4414.scala new file mode 100644 index 000000000000..2a2999ff34b7 --- /dev/null +++ b/tests/pos/i4414.scala @@ -0,0 +1,11 @@ +import scala.quoted._ + +object Test { + + def a[A: Type](): Unit = { + b[Expr[A]]() + a[A]() + } + + def b[A: Type](): Unit = ??? +}