Skip to content

Assertion failure for macros during separate compilation #7343

Closed
@anatoliykmetyuk

Description

@anatoliykmetyuk

Macros_1.scala:

import scala.quoted.{ QuoteContext, Expr }

trait M {
  def f: Any
}

inline def g(em: Expr[M])(given QuoteContext) = '{$em.f}

Macros_2.scala:

import scala.quoted.{ QuoteContext, Expr }

def h(m: Expr[M])(given QuoteContext): Expr[Any] = g(m)

Compile separately and the second one with -Ycheck:all, e.g.:

sbt:dotty> ;dotty-bootstrapped/dotc ../pg/i1/Macros_1.scala ;dotty-bootstrapped/dotc -Ycheck:all -classpath . ../pg/i1/Macros_2.scala

You will see:

Assertion failure
checking ../pg/i1/Macros_2.scala after phase reifyQuotes
exception while typing scala.internal.Quoted.exprQuote[Any] of class class dotty.tools.dotc.ast.Trees$TypeApply # 3160
exception while typing '{
  ${
    {
      def $anonfun(given evidence$1: quoted.QuoteContext): quoted.Expr[M] =
        {
          m
        }
      closure($anonfun)
    }
  }.f
} of class class dotty.tools.dotc.ast.Trees$Apply # 3164
exception while typing '{
  ${
    {
      def $anonfun(given evidence$1: quoted.QuoteContext): quoted.Expr[M] =
        {
          m
        }
      closure($anonfun)
    }
  }.f
}.apply of class class dotty.tools.dotc.ast.Trees$Select # 3165
exception while typing '{
  ${
    {
      def $anonfun(given evidence$1: quoted.QuoteContext): quoted.Expr[M] =
        {
          m
        }
      closure($anonfun)
    }
  }.f
}.apply(
  {
    x$2
  }
) of class class dotty.tools.dotc.ast.Trees$Apply # 3166
exception while typing {
  '{
    ${
      {
        def $anonfun(given evidence$1: quoted.QuoteContext): quoted.Expr[M] =
          {
            m
          }
        closure($anonfun)
      }
    }.f
  }.apply(
    {
      x$2
    }
  )
} of class class dotty.tools.dotc.ast.Trees$Inlined # 1351
exception while typing def h(m: quoted.Expr[M])(given x$2: quoted.QuoteContext): quoted.Expr[Any] =
  {
    '{
      ${
        {
          def $anonfun(given evidence$1: quoted.QuoteContext): quoted.Expr[M] =
            {
              m
            }
          closure($anonfun)
        }
      }.f
    }.apply(
      {
        x$2
      }
    )
  } of class class dotty.tools.dotc.ast.Trees$DefDef # 1352
exception while typing @scala.annotation.internal.SourceFile("../pg/i1/Macros_2.scala") final module
  class
 Macros_2$package$() extends Object(), _root_.scala.Serializable {
  this: Macros_2$package.type =>
  private def writeReplace(): AnyRef =
    new scala.runtime.ModuleSerializationProxy(classOf[Macros_2$package.type])
  def h(m: quoted.Expr[M])(given x$2: quoted.QuoteContext): quoted.Expr[Any] =
    {
      '{
        ${
          {
            def $anonfun(given evidence$1: quoted.QuoteContext): quoted.Expr[M]
               =
            {
              m
            }
            closure($anonfun)
          }
        }.f
      }.apply(
        {
          x$2
        }
      )
    }
} of class class dotty.tools.dotc.ast.Trees$TypeDef # 1362
exception while typing package <empty> {
  import scala.quoted.{QuoteContext, Expr}
  final lazy module val Macros_2$package: Macros_2$package$ =
    new Macros_2$package$()
  @scala.annotation.internal.SourceFile("../pg/i1/Macros_2.scala") final module
    class
   Macros_2$package$() extends Object(), _root_.scala.Serializable {
    this: Macros_2$package.type =>
    private def writeReplace(): AnyRef =
      new scala.runtime.ModuleSerializationProxy(classOf[Macros_2$package.type])
    def h(m: quoted.Expr[M])(given x$2: quoted.QuoteContext): quoted.Expr[Any]
       =
    {
      '{
        ${
          {
            def $anonfun(given evidence$1: quoted.QuoteContext): quoted.Expr[M]
               =
            {
              m
            }
            closure($anonfun)
          }
        }.f
      }.apply(
        {
          x$2
        }
      )
    }
  }
} of class class dotty.tools.dotc.ast.Trees$PackageDef # 1363
*** error while checking ../pg/i1/Macros_2.scala after phase reifyQuotes ***
exception occurred while compiling ../pg/i1/Macros_2.scala
java.lang.AssertionError: assertion failed while compiling ../pg/i1/Macros_2.scala
Exception in thread "main" java.lang.AssertionError: assertion failed
	at dotty.DottyPredef$.assertFail(DottyPredef.scala:16)
	at dotty.tools.dotc.transform.ReifyQuotes.checkPostCondition(ReifyQuotes.scala:80)
	at dotty.tools.dotc.transform.TreeChecker.dotty$tools$dotc$transform$TreeChecker$Checker$$_$typedUnadapted$$anonfun$1(TreeChecker.scala:318)
	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:318)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2153)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2165)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:286)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2241)
	at dotty.tools.dotc.typer.ReTyper.typedFunPart(ReTyper.scala:72)
	at dotty.tools.dotc.typer.Applications.typedTypeApply(Applications.scala:1001)
	at dotty.tools.dotc.typer.Typer.typedTypeApply(Typer.scala:83)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2079)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2117)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:301)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2153)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2165)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:286)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2241)
	at dotty.tools.dotc.typer.ReTyper.typedFunPart(ReTyper.scala:72)
	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:839)
	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:966)
	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:83)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2061)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2117)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:301)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2153)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2165)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:286)
	at dotty.tools.dotc.typer.ReTyper.typedSelect(ReTyper.scala:41)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedSelect(TreeChecker.scala:374)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2041)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2116)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:301)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2153)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2165)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:286)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2241)
	at dotty.tools.dotc.typer.ReTyper.typedFunPart(ReTyper.scala:72)
	at dotty.tools.dotc.typer.Applications.realApply$1(Applications.scala:839)
	at dotty.tools.dotc.typer.Applications.typedApply(Applications.scala:966)
	at dotty.tools.dotc.typer.Typer.typedApply(Typer.scala:83)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2061)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2117)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:301)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2153)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2151)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2165)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:286)
	at dotty.tools.dotc.typer.Typer.typedInlined(Typer.scala:1291)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedInlined$$anonfun$1(TreeChecker.scala:460)
	at dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:168)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedInlined(TreeChecker.scala:460)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2082)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2117)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:301)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2153)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2165)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:286)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2241)
	at dotty.tools.dotc.typer.Typer.typedDefDef(Typer.scala:1600)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedDefDef$$anonfun$2$$anonfun$1(TreeChecker.scala:431)
	at dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:168)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedDefDef$$anonfun$1(TreeChecker.scala:434)
	at dotty.tools.dotc.transform.TreeChecker$Checker.withDefinedSyms(TreeChecker.scala:168)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedDefDef(TreeChecker.scala:435)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2048)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2116)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:301)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2153)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2165)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:286)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2184)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2228)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:475)
	at dotty.tools.dotc.typer.Typer.typedClassDef(Typer.scala:1727)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedClassDef(TreeChecker.scala:415)
	at dotty.tools.dotc.typer.Typer.typedNamed$1(Typer.scala:2051)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2116)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:301)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2153)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2165)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:286)
	at dotty.tools.dotc.typer.Typer.traverse$1(Typer.scala:2184)
	at dotty.tools.dotc.typer.Typer.typedStats(Typer.scala:2228)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedStats(TreeChecker.scala:475)
	at dotty.tools.dotc.typer.Typer.typedPackageDef(Typer.scala:1852)
	at dotty.tools.dotc.typer.Typer.typedUnnamed$1(Typer.scala:2092)
	at dotty.tools.dotc.typer.Typer.typedUnadapted(Typer.scala:2117)
	at dotty.tools.dotc.typer.ReTyper.typedUnadapted(ReTyper.scala:123)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typedUnadapted(TreeChecker.scala:301)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2153)
	at dotty.tools.dotc.typer.Typer.typed(Typer.scala:2165)
	at dotty.tools.dotc.transform.TreeChecker$Checker.typed(TreeChecker.scala:286)
	at dotty.tools.dotc.typer.Typer.typedExpr(Typer.scala:2241)
	at dotty.tools.dotc.transform.TreeChecker.check(TreeChecker.scala:121)
	at dotty.tools.dotc.transform.TreeChecker.run(TreeChecker.scala:94)
	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:159)
	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:169)
	at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:177)
	at dotty.runtime.function.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
	at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:67)
	at dotty.tools.dotc.Run.compileUnits(Run.scala:184)
	at dotty.tools.dotc.Run.compileSources(Run.scala:121)
	at dotty.tools.dotc.Run.compile(Run.scala:104)
	at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
	at dotty.tools.dotc.Driver.process(Driver.scala:178)
	at dotty.tools.dotc.Driver.process(Driver.scala:147)
	at dotty.tools.dotc.Driver.process(Driver.scala:159)
	at dotty.tools.dotc.Driver.main(Driver.scala:186)
	at dotty.tools.dotc.Main.main(Main.scala)

Can be related to #7342.

Metadata

Metadata

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions