Skip to content

Cannot heal types in nested type quotes #8302

Closed
@nicolasstucki

Description

@nicolasstucki

minimized code

import scala.quoted._
def foo[T](using qctx: QuoteContext, tpe: Type[T]): Expr[Any] =
  '{
    type TT = T
    val t = '[TT]
    ???
  }

Crash output (click arrow to expand)

result after staging:
package <empty> {
  import scala.quoted._
  final lazy module val Foo$package: Foo$package$ = 
    new Foo$package$()
  final module class Foo$package$() extends Object(), _root_.scala.
    Serializable
   { this: Foo$package.type =>
    def foo[T >: Nothing <: Any](using qctx: quoted.QuoteContext, 
      tpe: quoted.Type[T]
    ): quoted.Expr[Any] = 
      '{
        {
          type TT = ${tpe}
          val t: quoted.Type[TT] = '[${tpe}]
          ???
        }
      }.apply(qctx)
  }
}


class dotty.tools.dotc.reporting.diagnostic.messages$Error: access to value tpe from wrong staging level:
 - the definition is at level 0,
 - but the access is at level 1. while compiling Foo.scala
Exception in thread "main" class dotty.tools.dotc.reporting.diagnostic.messages$Error at Foo.scala:<122..122>: access to value tpe from wrong staging level:
 - the definition is at level 0,
 - but the access is at level 1.
        at dotty.tools.dotc.reporting.Reporting.error(Reporter.scala:136)
        at dotty.tools.dotc.core.Contexts$Context.error(Contexts.scala:75)
        at dotty.tools.dotc.transform.PCPCheckAndHeal.levelError(PCPCheckAndHeal.scala:237)
        at dotty.tools.dotc.transform.PCPCheckAndHeal.dotty$tools$dotc$transform$PCPCheckAndHeal$$checkSymLevel(PCPCheckAndHeal.scala:183)
        at dotty.tools.dotc.transform.PCPCheckAndHeal.checkLevel(PCPCheckAndHeal.scala:99)
        at dotty.tools.dotc.transform.PCPCheckAndHeal.transform(PCPCheckAndHeal.scala:52)
        at dotty.tools.dotc.transform.TreeMapWithStages.op$1(TreeMapWithStages.scala:93)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:120)
        at dotty.tools.dotc.transform.PCPCheckAndHeal.transform(PCPCheckAndHeal.scala:52)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1321)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:101)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
        at dotty.tools.dotc.transform.TreeMapWithStages.op$1(TreeMapWithStages.scala:118)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:120)
        at dotty.tools.dotc.transform.PCPCheckAndHeal.transform(PCPCheckAndHeal.scala:51)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$2(Trees.scala:1348)
        at scala.collection.immutable.List.mapConserve(List.scala:444)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1348)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1346)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1272)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:89)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
        at dotty.tools.dotc.transform.TreeMapWithStages.op$1(TreeMapWithStages.scala:106)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:120)
        at dotty.tools.dotc.transform.PCPCheckAndHeal.transform(PCPCheckAndHeal.scala:52)
        at dotty.tools.dotc.transform.PCPCheckAndHeal.transformQuotation(PCPCheckAndHeal.scala:59)
        at dotty.tools.dotc.transform.TreeMapWithStages.op$1(TreeMapWithStages.scala:94)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:120)
        at dotty.tools.dotc.transform.PCPCheckAndHeal.transform(PCPCheckAndHeal.scala:52)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1252)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:117)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
        at dotty.tools.dotc.transform.TreeMapWithStages.op$1(TreeMapWithStages.scala:118)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:120)
        at dotty.tools.dotc.transform.PCPCheckAndHeal.transform(PCPCheckAndHeal.scala:52)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1258)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:117)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
        at dotty.tools.dotc.transform.TreeMapWithStages.op$1(TreeMapWithStages.scala:118)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:120)
        at dotty.tools.dotc.transform.PCPCheckAndHeal.transform(PCPCheckAndHeal.scala:52)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:97)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
        at dotty.tools.dotc.transform.TreeMapWithStages.op$1(TreeMapWithStages.scala:118)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:120)
        at dotty.tools.dotc.transform.PCPCheckAndHeal.transform(PCPCheckAndHeal.scala:51)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.traverse$1(TreeMapWithImplicits.scala:51)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transformStats(TreeMapWithImplicits.scala:58)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:108)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
        at dotty.tools.dotc.transform.TreeMapWithStages.op$1(TreeMapWithStages.scala:118)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:120)
        at dotty.tools.dotc.transform.PCPCheckAndHeal.transform(PCPCheckAndHeal.scala:51)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1328)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:101)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
        at dotty.tools.dotc.transform.TreeMapWithStages.op$1(TreeMapWithStages.scala:118)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:120)
        at dotty.tools.dotc.transform.PCPCheckAndHeal.transform(PCPCheckAndHeal.scala:51)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform$$anonfun$2(Trees.scala:1348)
        at scala.collection.immutable.List.mapConserve(List.scala:444)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1348)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transformStats(Trees.scala:1346)
        at dotty.tools.dotc.ast.Trees$Instance$TreeMap.transform(Trees.scala:1334)
        at dotty.tools.dotc.ast.TreeMapWithImplicits.transform(TreeMapWithImplicits.scala:101)
        at dotty.tools.dotc.transform.TreeMapWithStages.mapOverTree$1(TreeMapWithStages.scala:77)
        at dotty.tools.dotc.transform.TreeMapWithStages.op$1(TreeMapWithStages.scala:118)
        at dotty.tools.dotc.transform.TreeMapWithStages.transform(TreeMapWithStages.scala:120)
        at dotty.tools.dotc.transform.PCPCheckAndHeal.transform(PCPCheckAndHeal.scala:52)
        at dotty.tools.dotc.transform.Staging.checkPostCondition(Staging.scala:59)
        at dotty.tools.dotc.transform.TreeChecker.dotty$tools$dotc$transform$TreeChecker$Checker$$_$typedUnadapted$$anonfun$1(TreeChecker.scala:321)
        at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.immutable.List.foreach(List.scala:305)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:321)
        at dotty.tools.dotc.typer.Typer.op$1(Typer.scala:2247)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2256)
        at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2259)
        at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:289)
        at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2367)
        at dotty.tools.dotc.transform.TreeChecker.check(TreeChecker.scala:124)
        at dotty.tools.dotc.transform.TreeChecker.run(TreeChecker.scala:97)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:315)
        at scala.collection.immutable.List.map(List.scala:219)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:316)
        at dotty.tools.dotc.Run.runPhases$4$$anonfun$4(Run.scala:167)
        at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at dotty.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1323)
        at dotty.tools.dotc.Run.runPhases$5(Run.scala:177)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:185)
        at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:64)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:192)
        at dotty.tools.dotc.Run.compileSources(Run.scala:129)
        at dotty.tools.dotc.Run.compile(Run.scala:112)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:36)
        at dotty.tools.dotc.Driver.process(Driver.scala:189)
        at dotty.tools.dotc.Driver.process(Driver.scala:158)
        at dotty.tools.dotc.Driver.process(Driver.scala:170)
        at dotty.tools.dotc.Driver.main(Driver.scala:197)
        at dotty.tools.dotc.Main.main(Main.scala)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions