Skip to content

-Ycheck returns non-empty constraint assertion error from an inline method calling a macro #16331

Closed
@jchyb

Description

@jchyb

Compiler version

3.2.1 and previous, also tested on d3c1c4e

Minimized code

Compiled with -Ycheck:inlining (or -Ycheck:all) and -Xprint:Ycheck

//macro.scala
import scala.quoted._

object Macro {
  transparent inline def macroDef[A](): Int = ${ macroDefImpl() }
  def macroDefImpl()(using q: Quotes): Expr[Int] = '{0}
}
//main.scala
object Main {
  inline def inlineDef[A](): Any = Macro.macroDef()
  def main(args: Array[String]) = {
    inlineDef()
  }
}

Output

checking i15971/macro.scala after phase inlining
java.lang.AssertionError: assertion failed: non-empty constraint at end of inlining:  uninstantiated variables: A
 constrained types: [A](tup: Any): HeadTail
 bounds:
     A
 ordering:
 co-deps:
 contra-deps:
, ownedVars = A while running Ycheck on i15971/macro.scala
exception occurred while compiling i15971/macro.scala
Exception in thread "main" java.lang.AssertionError: assertion failed: non-empty constraint at end of inlining:  uninstantiated variables: A
 constrained types: [A](tup: Any): HeadTail
 bounds:
     A
 ordering:
 co-deps:
 contra-deps:
, ownedVars = A while compiling i15971/main.scala, i15971/macro.scala
java.lang.AssertionError: assertion failed: non-empty constraint at end of inlining:  uninstantiated variables: A
 constrained types: [A](tup: Any): HeadTail
 bounds:
     A
 ordering:
 co-deps:
 contra-deps:
, ownedVars = A
        at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
        at dotty.tools.dotc.transform.TreeChecker.check(TreeChecker.scala:130)
        at dotty.tools.dotc.transform.TreeChecker.run(TreeChecker.scala:110)
        at dotty.tools.dotc.core.Phases$Phase.runOn$$anonfun$1(Phases.scala:324)
        at scala.collection.immutable.List.map(List.scala:246)
        at dotty.tools.dotc.core.Phases$Phase.runOn(Phases.scala:328)
        at dotty.tools.dotc.Run.runPhases$1$$anonfun$1(Run.scala:244)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
        at scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
        at scala.collection.ArrayOps$.foreach$extension(ArrayOps.scala:1321)
        at dotty.tools.dotc.Run.runPhases$1(Run.scala:260)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$1(Run.scala:268)
        at dotty.tools.dotc.Run.compileUnits$$anonfun$adapted$1(Run.scala:277)
        at dotty.tools.dotc.util.Stats$.maybeMonitored(Stats.scala:68)
        at dotty.tools.dotc.Run.compileUnits(Run.scala:277)
        at dotty.tools.dotc.Run.compileSources(Run.scala:195)
        at dotty.tools.dotc.Run.compile(Run.scala:179)
        at dotty.tools.dotc.Driver.doCompile(Driver.scala:35)
        at dotty.tools.dotc.Driver.process(Driver.scala:195)
        at dotty.tools.dotc.Driver.process(Driver.scala:163)
        at dotty.tools.dotc.Driver.process(Driver.scala:175)
        at dotty.tools.dotc.Driver.main(Driver.scala:205)
        at dotty.tools.dotc.Main.main(Main.scala)

Expectation

Should not fail the checker phase. Heavily based on #15971 (the minimization), but unrelated the binding issue presented there. Tried to find the cause, unsuccessfully. For now all I found is that this seems to be related to the suspend mechanism, performed after expanding a macro. Hopefully I will be able to come back to this one day.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions