Skip to content

Commit d15c72d

Browse files
committed
Force read unpickled trees to avoid Ycheck failure
1 parent def8b69 commit d15c72d

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,17 @@ object PickledQuotes {
5353

5454
/** Transform the expression into its fully spliced Tree */
5555
def quotedExprToTree[T](expr: quoted.Expr[T])(implicit ctx: Context): Tree = expr match {
56-
case expr: TastyExpr[_] => unpickleExpr(expr)
56+
case expr: TastyExpr[_] =>
57+
val unpickled = unpickleExpr(expr)
58+
val force = new TreeTraverser {
59+
def traverse(tree: tpd.Tree)(implicit ctx: Context): Unit = traverseChildren(tree)
60+
}
61+
force.traverse(unpickled)
62+
unpickled
5763
case expr: LiftedExpr[T] =>
5864
expr.value match {
5965
case value: Class[_] => ref(defn.Predef_classOf).appliedToType(classToType(value))
60-
case value=> Literal(Constant(value))
66+
case value => Literal(Constant(value))
6167
}
6268
case expr: TreeExpr[Tree] @unchecked => expr.tree
6369
case expr: FunctionAppliedTo[_, _] =>

tests/run/quote-force.check

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
foo Location(List(a, b, c, d, e, f))

tests/run/quote-force/quoted_1.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import scala.quoted._
2+
3+
case class Location(owners: List[String])
4+
5+
object Location {
6+
7+
implicit inline def location: Location = ~impl
8+
9+
def impl: Expr[Location] = {
10+
val list = List("a", "b", "c", "d", "e", "f")
11+
'(new Location(~list.toExpr))
12+
}
13+
14+
private implicit def ListIsLiftable[T : Liftable : Type]: Liftable[List[T]] = {
15+
case x :: xs => '{ ~x.toExpr :: ~xs.toExpr }
16+
case Nil => '{ List.empty[T] }
17+
}
18+
}

tests/run/quote-force/quoted_2.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Location._
2+
3+
object Test {
4+
val loc1 = location
5+
def main(args: Array[String]): Unit = {
6+
foo(loc1)
7+
}
8+
9+
def foo(implicit location: Location): Unit = {
10+
println("foo " + location)
11+
}
12+
}

0 commit comments

Comments
 (0)