Skip to content

Incorrect line positions in macro expansion #5629

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
liufengyun opened this issue Dec 17, 2018 · 2 comments
Closed

Incorrect line positions in macro expansion #5629

liufengyun opened this issue Dec 17, 2018 · 2 comments

Comments

@liufengyun
Copy link
Contributor

liufengyun commented Dec 17, 2018

This is an error encountered when working with ScalaTest (#5491 ). Given the macro definition below:

import scala.quoted._
import scala.tasty._

object scalatest {
  inline def assert(condition: => Boolean): Unit = ~assertImpl('(condition), '(""))

  def assertImpl(cond: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] = {
    import refl._
    val b = cond.unseal.underlyingArgument.seal[Boolean]
    '{ scala.Predef.assert(~b) }
  }

  inline def thisLineNumber = ~thisLineNumberImpl

  def thisLineNumberImpl(implicit refl: Reflection): Expr[Int] = {
    import refl._
    refl.rootPosition.startLine.toExpr
  }
}

The following code fails at runtime:

object Test {
  import scalatest._

  def main(args: Array[String]): Unit = {
    val startLine = thisLineNumber
    assert(thisLineNumber == startLine + 1)
    // scala.Predef.assert(thisLineNumber == startLine + 1)  // OK
  }
}
@nicolasstucki
Copy link
Contributor

The issue is that underlyingArgument is dropping the Inlined node

liufengyun added a commit to dotty-staging/scalatest that referenced this issue Dec 17, 2018
Now the line numbers are correct by accident. A walkaround for the issue blow:

scala/scala3#5629
@liufengyun
Copy link
Contributor Author

The commit in dotty-staging/scalatest@56e319e magically avoids the error.

liufengyun added a commit that referenced this issue Mar 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants