Skip to content

Commit 304ffae

Browse files
author
Aggelos Biboudis
authored
Merge pull request #4481 from dotty-staging/fix-#4414
Fix #4414: Use original type in generated unpickle{Expr|Type}
2 parents d97bce0 + 4c54db1 commit 304ffae

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -386,17 +386,17 @@ class ReifyQuotes extends MacroTransformWithImplicits with InfoTransformer {
386386
}
387387
case _=>
388388
val (body1, splices) = nested(isQuote = true).split(body)
389-
pickledQuote(body1, splices, isType).withPos(quote.pos)
389+
pickledQuote(body1, splices, body.tpe, isType).withPos(quote.pos)
390390
}
391391
}
392392

393-
private def pickledQuote(body: Tree, splices: List[Tree], isType: Boolean)(implicit ctx: Context) = {
393+
private def pickledQuote(body: Tree, splices: List[Tree], originalTp: Type, isType: Boolean)(implicit ctx: Context) = {
394394
def pickleAsValue[T](value: T) =
395-
ref(defn.Unpickler_liftedExpr).appliedToType(body.tpe.widen).appliedTo(Literal(Constant(value)))
395+
ref(defn.Unpickler_liftedExpr).appliedToType(originalTp.widen).appliedTo(Literal(Constant(value)))
396396
def pickleAsTasty() = {
397397
val meth =
398-
if (isType) ref(defn.Unpickler_unpickleType).appliedToType(body.tpe)
399-
else ref(defn.Unpickler_unpickleExpr).appliedToType(body.tpe.widen)
398+
if (isType) ref(defn.Unpickler_unpickleType).appliedToType(originalTp)
399+
else ref(defn.Unpickler_unpickleExpr).appliedToType(originalTp.widen)
400400
meth.appliedTo(
401401
liftList(PickledQuotes.pickleQuote(body).map(x => Literal(Constant(x))), defn.StringType),
402402
liftList(splices, defn.AnyType))

tests/pos/i4414.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import scala.quoted._
2+
3+
object Test {
4+
5+
def a[A: Type](): Unit = {
6+
b[Expr[A]]()
7+
a[A]()
8+
}
9+
10+
def b[A: Type](): Unit = ???
11+
}

0 commit comments

Comments
 (0)