Skip to content

Quotes blow up when trying to do 2-staged programming at runtime #6754

@anatoliykmetyuk

Description

@anatoliykmetyuk

minimized code

import scala.quoted._

object Main {
  implicit val tbx: scala.quoted.Toolbox = scala.quoted.Toolbox.make(getClass.getClassLoader)

  def main(args: Array[String]): Unit = {
    val y: Expr[Unit] = '{
      val x: Expr[Unit] = '{println("foo")}
      x.run
    }
    y.run
  }
}
Stack trace
sbt:core> run
[info] Compiling 1 Scala source to /Users/anatolii/Projects/dotty/playground/core/target/scala-0.16/classes ...
[info] Done compiling.
[info] Packaging /Users/anatolii/Projects/dotty/playground/core/target/scala-0.16/core_0.16-0.1.0.jar ...
[info] Done packaging.
[info] Running playground.Main
exception while typing scala.internal.Quoted.exprQuote of class class dotty.tools.dotc.ast.Trees$Ident # 1056
exception while typing scala.internal.Quoted.exprQuote[Unit] of class class dotty.tools.dotc.ast.Trees$TypeApply # 1083
exception while typing '{println("foo")} of class class dotty.tools.dotc.ast.Trees$Apply # 1084
exception while typing val x: quoted.Expr[Unit] = '{println("foo")} of class class dotty.tools.dotc.ast.Trees$ValDef # 1085
exception while typing {
  val x: quoted.Expr[Unit] = '{println("foo")}
  x.run(playground.Main.tbx)
} of class class dotty.tools.dotc.ast.Trees$Block # 1086
exception while typing {
  {
    val x: quoted.Expr[Unit] = '{println("foo")}
    x.run(playground.Main.tbx)
  }
} of class class dotty.tools.dotc.ast.Trees$Inlined # 1087
exception while typing def apply: Any =
  {
    {
      val x: quoted.Expr[Unit] = '{println("foo")}
      x.run(playground.Main.tbx)
    }
  } of class class dotty.tools.dotc.ast.Trees$DefDef # 37
exception while typing class Generated$Code$From$Quoted() extends Object() {
  def apply: Any =
    {
      {
        val x: quoted.Expr[Unit] = '{println("foo")}
        x.run(playground.Main.tbx)
      }
    }
} of class class dotty.tools.dotc.ast.Trees$TypeDef # 39
exception while typing package _root_ {
  class Generated$Code$From$Quoted() extends Object() {
    def apply: Any =
      {
        {
          val x: quoted.Expr[Unit] = '{println("foo")}
          x.run(playground.Main.tbx)
        }
      }
  }
} of class class dotty.tools.dotc.ast.Trees$PackageDef # 40
[error] (run-main-2f) class dotty.tools.dotc.reporting.diagnostic.messages$Error at /Users/anatolii/Projects/dotty/playground/core/src/main/scala/playground/Main.scala:<249..249>: Reference to method exprQuote in object Quoted should not have survived,
[error]                  |it should have been processed and eliminated during expansion of an enclosing macro or term erasure.
[error] class dotty.tools.dotc.reporting.diagnostic.messages$Error at /Users/anatolii/Projects/dotty/playground/core/src/main/scala/playground/Main.scala:<249..249>: Reference to method exprQuote in object Quoted should not have survived,
[error]                  |it should have been processed and eliminated during expansion of an enclosing macro or term erasure.
[error] 	at dotty.tools.dotc.reporting.Reporting.error(Reporter.scala:136)
[error] 	at dotty.tools.dotc.core.Contexts$Context.error(Contexts.scala:71)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.checkNotErased(Erasure.scala:341)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.typedIdent(Erasure.scala:397)
[error] 	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2130)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2204)
[error] 	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2239)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2251)
[error] 	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2329)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.typedTypeApply(Erasure.scala:521)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2168)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2205)
[error] 	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2239)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2251)
[error] 	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2329)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.typedApply(Erasure.scala:539)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2151)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2205)
[error] 	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2239)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2251)
[error] 	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2329)
[error] 	at dotty.tools.dotc.typer.Typer.typedValDef(Typer.scala:1483)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.typedValDef(Erasure.scala:596)
[error] 	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2135)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2204)
[error] 	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2239)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2251)
[error] 	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2270)
[error] 	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2316)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:738)
[error] 	at dotty.tools.dotc.typer.Typer.typedBlockStats(Typer.scala:711)
[error] 	at dotty.tools.dotc.typer.Typer.typedBlock(Typer.scala:714)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2158)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2205)
[error] 	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2239)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2251)
[error] 	at dotty.tools.dotc.typer.Typer.typedInlined(Typer.scala:1240)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.typedInlined(Erasure.scala:588)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2171)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2205)
[error] 	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2239)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2237)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2251)
[error] 	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2329)
[error] 	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1549)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.typedDefDef(Erasure.scala:631)
[error] 	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2138)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2204)
[error] 	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2239)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2251)
[error] 	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2270)
[error] 	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2316)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:738)
[error] 	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1678)
[error] 	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2141)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2204)
[error] 	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2239)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2251)
[error] 	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2270)
[error] 	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2316)
[error] 	at dotty.tools.dotc.transform.Erasure$Typer.typedStats(Erasure.scala:738)
[error] 	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1802)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2181)
[error] 	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2205)
[error] 	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:124)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2239)
[error] 	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2251)
[error] 	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2329)
[error] 	at dotty.tools.dotc.transform.Erasure.run(Erasure.scala:100)
[error] 	at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:316)
[error] 	at scala.collection.immutable.List.map(List.scala:286)
[error] 	at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:318)
[error] 	at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:158)
[error] 	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
[error] 	at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
[error] 	at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
[error] 	at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33)
[error] 	at scala.collection.mutable.ArrayOps$ofRef.foreach(ArrayOps.scala:198)
[error] 	at dotty.tools.dotc.Run.runPhases$5(Run.scala:170)
[error] 	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:178)
[error] 	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
[error] 	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:102)
[error] 	at dotty.tools.dotc.Run.compileUnits(Run.scala:185)
[error] 	at dotty.tools.dotc.Run.compileUnits(Run.scala:125)
[error] 	at dotty.tools.dotc.quoted.QuoteCompiler$ExprRun.compileExpr(QuoteCompiler.scala:90)
[error] 	at dotty.tools.dotc.quoted.QuoteDriver.run(QuoteDriver.scala:37)
[error] 	at dotty.tools.dotc.quoted.ToolboxImpl$$anon$1.run(ToolboxImpl.scala:28)
[error] 	at scala.quoted.Expr.run(Expr.scala:11)
[error] 	at playground.Main$.main(Main.scala:13)
[error] 	at playground.Main.main(Main.scala)
[error] 	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
[error] 	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
[error] 	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
[error] 	at java.lang.reflect.Method.invoke(Method.java:498)
[error] Nonzero exit code: 1
[error] (Compile / run) Nonzero exit code: 1
[error] Total time: 5 s, completed Jun 26, 2019 5:09:56 PM

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions