Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
deusaquilus opened this issue Dec 21, 2020 · 1 comment · Fixed by #11026
Closed

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

deusaquilus opened this issue Dec 21, 2020 · 1 comment · Fixed by #11026
Milestone

Comments

@deusaquilus
Copy link
Contributor

deusaquilus commented Dec 21, 2020

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.

@deusaquilus
Copy link
Contributor Author

deusaquilus commented Dec 21, 2020

Also note that if you change 'ent' to 'inline inside DSL compile will work.

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

In Quill I have an example where this will fail even if 'ent' is inline but I haven't been able to reproduce that one.

@smarter smarter added this to the 3.0.0-RC1 milestone Dec 21, 2020
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 7, 2021
nicolasstucki added a commit to dotty-staging/dotty that referenced this issue Jan 7, 2021
@Kordyjan Kordyjan modified the milestones: 3.0.0-RC1, 3.0.0 Aug 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants