Skip to content

Commit 17ba04c

Browse files
committed
Fix bug while unpickling splices in quotes
1 parent 9284c90 commit 17ba04c

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ import scala.collection.{ mutable, immutable }
1919
import config.Printers.pickling
2020
import typer.Checking
2121
import config.Config
22+
import dotty.tools.dotc.quoted.PickledQuotes
23+
import dotty.tools.dotc.interpreter.RawExpr
24+
import scala.quoted.Expr
2225

2326
/** Unpickler for typed trees
2427
* @param reader the reader from which to unpickle
@@ -1030,8 +1033,10 @@ class TreeUnpickler(reader: TastyReader,
10301033
val idx = readNat()
10311034
val args = until(end)(readTerm())
10321035
val splice = splices(idx)
1033-
if (args.isEmpty) splice.asInstanceOf[Tree]
1034-
else splice.asInstanceOf[Seq[Any] => Tree](args)
1036+
val expr =
1037+
if (args.isEmpty) splice.asInstanceOf[Expr[_]]
1038+
else splice.asInstanceOf[Seq[Any] => Expr[_]](args.map(arg => new RawExpr(arg)))
1039+
PickledQuotes.quotedToTree(expr)
10351040
case _ =>
10361041
readPathTerm()
10371042
}

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ object PickledQuotes {
3434
/** Unpickle the tree contained in the TastyQuoted */
3535
private def unpickleQuote(expr: quoted.TastyQuoted)(implicit ctx: Context): Tree = {
3636
val tastyBytes = TastyString.stringToTasty(expr.tasty)
37-
val splices = expr.args.map {
38-
case arg: quoted.Quoted => quotedToTree(arg)
39-
case arg => arg
40-
}
41-
val unpickled = unpickle(tastyBytes, splices)
37+
val unpickled = unpickle(tastyBytes, expr.args)
4238
unpickled match { // Expects `package _root_ { val ': Any = <tree> }`
4339
case PackageDef(_, (vdef: ValDef) :: Nil) => vdef.rhs
4440
}

tests/run/quote-and-splice.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@
44
3
55
1.0
66
5.0
7+
25.0
8+
125.0

tests/run/quote-and-splice/Test_2.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,8 @@ object Test {
88
println(macro3(1))
99
println(power(0, 5))
1010
println(power(1, 5))
11-
// FIXME
12-
// println(power(2, 5))
13-
// println(power(3, 5))
11+
println(power(2, 5))
12+
println(power(3, 5))
1413
}
1514

1615
}

0 commit comments

Comments
 (0)