Skip to content

Position Error when using chained inline defs with same file #10880

@deusaquilus

Description

@deusaquilus

Okay, this one is a bit more complex.

Start by creating a macro that declares some inline defs and then uses them:

trait Ent(name: String)
case class MyContent(key: String, value: String)
case class MyInsert(key: String)

object Dsl {
  inline def ent: Ent = new Ent("something") {}
  extension (ent: Ent)
    inline def content(inline ins: MyInsert) = MyContent(ins.key, "blah")
}

Then define a macro that expects an input:

case class MyQuoted(val ast: String, sub: String)

object MyQuoteMacro {
  inline def myquote(inline content: MyContent): MyQuoted = ${ MyQuoteMacro.apply('content) }
  def apply(content: Expr[MyContent])(using Quotes): Expr[MyQuoted] = {
    import quotes.reflect._
    '{ MyQuoted($content.key, ???) }
  }
}

Then define a macro that does a simple field extraction:

object PullAst {
  def applyImpl(quoted: Expr[MyQuoted])(using qctx: Quotes): Expr[String] =
    '{ $quoted.ast.toString }

  inline def apply(inline quoted: MyQuoted): String = 
    ${ applyImpl('quoted) }
}

Then define a macro to test these. Make sure it is in the same compilation path (i.e. when I put it into src/test/scala it will compile fine).

object Test {
  import Dsl._

  inline def q2 = MyQuoteMacro.myquote(ent.content(MyInsert("Foo")))

  def main(args: Array[String]): Unit = {
    println( PullAst.apply( q2 ) )
  }
}

Compile it and voila!

[error] stack trace is suppressed; run last Compile / compileIncremental for the full output
[error] (Compile / compileIncremental) java.lang.AssertionError: assertion failed: position not set for {
[error]   val ent$proxy2: io.getquill.Ent = 
[error]     {
[error]       final class $anon() extends Object(), io.getquill.Ent("something") {}
[error]       new $anon():io.getquill.Ent
[error]     }:io.getquill.Ent
[error]   "Foo"

I checked this into a branch of my pos_bug_reproduction repo:
https://github.com/deusaquilus/pos_bug_reproduction/tree/more_complex

Also note that this has to be a compile-from-scratch. If you compile the macros first and then 'test' in separate cycles (as is the case of Test is in src/main/scala) then the error will not happen.

Expectation

Compile should succeed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions