Skip to content

Commit 87411b5

Browse files
committed
Add types to unpickle methods
1 parent 8ed2487 commit 87411b5

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

compiler/src/dotty/tools/dotc/quoted/QuoteContextImpl.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2628,13 +2628,13 @@ class QuoteContextImpl private (ctx: Context) extends QuoteContext, scala.intern
26282628

26292629
end reflect
26302630

2631-
def unpickleExpr(pickledQuote: PickledQuote): scala.quoted.Expr[Any] =
2631+
def unpickleExpr[T](pickledQuote: PickledQuote): scala.quoted.Expr[T] =
26322632
val tree = PickledQuotes.unpickleTerm(pickledQuote)(using reflect.rootContext)
2633-
new scala.internal.quoted.Expr(tree, hash)
2633+
new scala.internal.quoted.Expr(tree, hash).asInstanceOf[scala.quoted.Expr[T]]
26342634

2635-
def unpickleType(pickledQuote: PickledQuote): scala.quoted.Type[?] =
2635+
def unpickleType[T <: AnyKind](pickledQuote: PickledQuote): scala.quoted.Type[T] =
26362636
val tree = PickledQuotes.unpickleTypeTree(pickledQuote)(using reflect.rootContext)
2637-
new scala.internal.quoted.Type(tree, hash)
2637+
new scala.internal.quoted.Type(tree, hash).asInstanceOf[scala.quoted.Type[T]]
26382638

26392639
def exprMatch(scrutinee: scala.quoted.Expr[Any], pattern: scala.quoted.Expr[Any]): Option[Tuple] =
26402640
treeMatch(scrutinee.unseal(using this), pattern.unseal(using this))

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,9 @@ class ReifyQuotes extends MacroTransform {
194194
*
195195
* Generate the code
196196
* ```scala
197-
* qctx => qctx.asInstanceOf[QuoteContextInternal].<unpickleExpr|unpickleType>(
197+
* qctx => qctx.asInstanceOf[QuoteContextInternal].<unpickleExpr|unpickleType>[<type>](
198198
* <pickledQuote>
199-
* ).asInstanceOf[scala.quoted.<Expr|Type>[<type>]]
199+
* )
200200
* ```
201201
* this closure is always applied directly to the actual context and the BetaReduce phase removes it.
202202
*/
@@ -211,7 +211,7 @@ class ReifyQuotes extends MacroTransform {
211211
def callUnpickle(ts: List[Tree]) = {
212212
val qctx = ts.head.asInstance(defn.QuoteContextInternalClass.typeRef)
213213
val unpickleMethName = if isType then "unpickleType" else "unpickleExpr"
214-
qctx.select(unpickleMethName.toTermName).appliedTo(pickledQuote).asInstance(quotedType)
214+
qctx.select(unpickleMethName.toTermName).appliedToType(originalTp).appliedTo(pickledQuote)
215215
}
216216
Lambda(lambdaTpe, callUnpickle).withSpan(body.span)
217217
}

library/src/scala/internal/quoted/QuoteContextInternal.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ trait QuoteContextInternal { self: scala.quoted.QuoteContext =>
1010
/** Unpickle `repr` which represents a pickled `Expr` tree,
1111
* replacing splice nodes with `holes`
1212
*/
13-
def unpickleExpr(pickledQuote: PickledQuote): scala.quoted.Expr[Any]
13+
def unpickleExpr[T](pickledQuote: PickledQuote): scala.quoted.Expr[T]
1414

1515
/** Unpickle `repr` which represents a pickled `Type` tree,
1616
* replacing splice nodes with `holes`
1717
*/
18-
def unpickleType(pickledQuote: PickledQuote): scala.quoted.Type[?]
18+
def unpickleType[T <: AnyKind](pickledQuote: PickledQuote): scala.quoted.Type[T]
1919

2020
/** Pattern matches the scrutinee against the pattern and returns a tuple
2121
* with the matched holes if successful.

0 commit comments

Comments
 (0)