Closed
Description
The code in the quote in f
cannot be unpickled
import dotty.tools.dotc.quoted.Runners._
import scala.quoted._
object Test {
def main(args: Array[String]): Unit = {
def f[T](x: Expr[T])(implicit t: Type[T]) = '{
val z = ~x
}
println(f('(2))(Type.IntTag).show)
}
}
This quote will be pickled as
type T = [[1| ]]
{
val z: T = [[0| ]]
()
}
After ReifyQuotes
the tree is
package <empty> {
import dotty.tools.dotc.quoted.Runners._
import scala.quoted._
final lazy module val Test: Test$ = new Test$()
@scala.annotation.internal.SourceFile("Foo.scala") final module class Test$()
extends
Object() { this: Test.type =>
def main(args: Array[String]): Unit =
{
def f[T >: Nothing <: Any](x: quoted.Expr[T])(implicit t: quoted.Type[T]
)
: scala.quoted.Expr[Unit] =
scala.runtime.quoted.Unpickler.unpickleExpr[Unit](
scala.collection.immutable.Nil.::[String](
"\\¡«\037\0203\0200\00\00\00\00\00\00\00\00\00\00\00\00\016\02M0£\01\0204ASTs\01\0206_root_\01\0201\'\01\0203Any\01\0205scala\01\0201z\01\0201T\0200¤\0200¢6\0201\0201\0236\0202u\02036\0204\0214\0226\0214\0211\02\0201\0206\02055\0230ÿ\0201\0200\0203\0211\0206£\0205ÿ\0201\02012\0235\025\025"
)
, [x,new scala.quoted.Type[T]() : Any])
println(
f[Int](
scala.runtime.quoted.Unpickler.unpickleExpr[Int](
scala.collection.immutable.Nil.::[String](
"\\¡«\037\0203\0200\00\00\00\00\00\00\00\00\00\00\00\00\n%fð\0235\01\0204ASTs\01\0206_root_\01\0201\'\01\0203Any\01\0205scala\0200\0216\0200\02146\0201\0201\0210\0202u\02036\0204<\0202\025"
)
, [ : Any])
)(quoted.Type.IntTag).show(
dotty.tools.dotc.quoted.Runners.runner[Unit]
)
)
}
}
}
Note that the arguments for the holes are x
and new scala.quoted.Type[T]()
hence when unpickling we get an instance of scala.quoted.Type
with an erased T
. Instead of new scala.quoted.Type[T]()
we should have t
.
If we have
def f[T](x: Expr[T])(implicit t: Type[T]) = '{
val z: ~t= ~x
}
then the hole receives the t
and works as expected.