Skip to content

Prepare inlining of quotes transforms too much #14603

Closed
@nicolasstucki

Description

@nicolasstucki

The bug in the macro implementation was fixed upstream. The fact that compiler was crashing isn't a bug per-se, given -Xcheck-macros (same if it were -Ycheck) errors out.

Currently, however this smaller minimisation of the macro implementation doesn't even compile, because "prepare inlineable" widens a prefix (type avoidance) which fails -Ycheck:

// Verify.scala
import scala.language.experimental.macros
import scala.quoted.*

class Runtime

class Macro(using qctx: Quotes) {
  import qctx.reflect._

  def apply[A: Type](x: Expr[A]): Expr[Unit] = {
    '{
      val rt: Runtime = ???
      ${Block(doExprs('{ rt }.asTerm), '{ () }.asTerm).asExprOf[Unit]}
    }
  }

  private def doExprs(rt: Term): List[Term] = Nil
}
Fatal compiler crash when compiling: tests/pos-macros/i7128:
assertion failed: Found:    quoted.Quotes#reflect.Term2s
Required: Macro.this.qctx.reflect.Term
found: type Term in trait reflectModule with type Term, flags = <deferred> <touched>, underlying = quoted.Quotes#reflect.Term,  <: quoted.Quotes#reflect.Statement, quoted.Quotes#reflect.Statement,  <: quoted.Quotes#reflect.Tree, quoted.Quotes#reflect.Tree,  <: AnyRef, AnyRef,  = Object, Object, Any with Matchable {...}
expected: type Term in trait reflectModule with type Term, flags = <deferred> <touched>, underlying = Macro.this.qctx.reflect.Term,  <: Macro.this.qctx.reflect.Statement, Macro.this.qctx.reflect.Statement,  <: Macro.this.qctx.reflect.Tree, Macro.this.qctx.reflect.Tree,  <: AnyRef, AnyRef,  = Object, Object, Any with Matchable {...}
tree = this.inline$qctx.reflect.asTerm('{rt}.apply(evidence$2))
	at scala.runtime.Scala3RunTime$.assertFailed(Scala3RunTime.scala:8)
	at dotty.tools.dotc.transform.TreeChecker$Checker.adapt(TreeChecker.scala:598)
	at dotty.tools.dotc.typer.ProtoTypes$FunProto.typedArg(ProtoTypes.scala:463)
	at dotty.tools.dotc.typer.Applications$ApplyToUntyped.typedArg(Applications.scala:866)

Nico to close and spin off an issue for that.

Originally posted by @dwijnand in #7128 (comment)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions