From b10eb98bd8968f39936f42c76091d19ab33f83c2 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Thu, 11 Jul 2019 10:17:28 +0200 Subject: [PATCH] Type internal splice representation Ycheck will be able to check the types of the splices generated by ReifyQuotes --- compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala | 5 ++++- library/src/scala/runtime/quoted/Unpickler.scala | 4 ++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala index 3e28b4a12ffb..3c65c69cc83f 100644 --- a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala @@ -229,9 +229,12 @@ class ReifyQuotes extends MacroTransform { val meth = if (isType) ref(defn.Unpickler_unpickleType).appliedToType(originalTp) else ref(defn.Unpickler_unpickleExpr).appliedToType(originalTp.widen) + val spliceResType = + if(isType) defn.QuotedTypeType.appliedTo(WildcardType) + else defn.QuotedExprType.appliedTo(defn.AnyType) | defn.QuotedTypeType.appliedTo(WildcardType) meth.appliedTo( liftList(PickledQuotes.pickleQuote(body).map(x => Literal(Constant(x))), defn.StringType), - liftList(splices, defn.AnyType)) + liftList(splices, defn.FunctionType(1).appliedTo(defn.SeqType.appliedTo(defn.AnyType), spliceResType))) } if (splices.nonEmpty) pickleAsTasty() else if (isType) { diff --git a/library/src/scala/runtime/quoted/Unpickler.scala b/library/src/scala/runtime/quoted/Unpickler.scala index 63eea27617e1..ab538a7b2d7d 100644 --- a/library/src/scala/runtime/quoted/Unpickler.scala +++ b/library/src/scala/runtime/quoted/Unpickler.scala @@ -14,10 +14,10 @@ object Unpickler { /** Unpickle `repr` which represents a pickled `Expr` tree, * replacing splice nodes with `args` */ - def unpickleExpr[T](repr: Pickled, args: Seq[Any]): Expr[T] = new TastyExpr[T](repr, args) + def unpickleExpr[T](repr: Pickled, args: Seq[Seq[Any] => (Expr[Any] | Type[_])]): Expr[T] = new TastyExpr[T](repr, args) /** Unpickle `repr` which represents a pickled `Type` tree, * replacing splice nodes with `args` */ - def unpickleType[T](repr: Pickled, args: Seq[Any]): Type[T] = new TastyType[T](repr, args) + def unpickleType[T](repr: Pickled, args: Seq[Seq[Any] => Type[_]]): Type[T] = new TastyType[T](repr, args) }