Skip to content

Macros: Imprecise error for string lifting #5547

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 Nov 30, 2018 · 4 comments
Closed

Macros: Imprecise error for string lifting #5547

liufengyun opened this issue Nov 30, 2018 · 4 comments

Comments

@liufengyun
Copy link
Contributor

The following code results in compilation error:

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

object scalatest {
  // inline def assert(condition: => Boolean): Unit =       // ok
  //  ~assertImpl('(condition), '("")) 
  inline def assert(condition: => Boolean): Unit =          // error
    ~assertImpl('(condition), "".toExpr)

  def assertImpl(condition: Expr[Boolean], clue: Expr[Any])(implicit refl: Reflection): Expr[Unit] =
    '(())
}

Error message:

6 |  inline def assert(condition: => Boolean): Unit = ~assertImpl('(condition), "".toExpr)
  |                                            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |        Malformed macro.
  |
  |        Expected the ~ to be at the top of the RHS:
  |          inline def foo(inline x: X, ..., y: Y): Int = ~impl(x, ... '(y))
  |
  |         * The contents of the splice must call a static method
  |         * All arguments must be quoted or inline
@liufengyun liufengyun changed the title Macors: Incorrect error for string lifting Macros: Incorrect error for string lifting Nov 30, 2018
@liufengyun liufengyun mentioned this issue Nov 30, 2018
66 tasks
@nicolasstucki
Copy link
Contributor

This error is correct. It is just not precise.

"".toExpr should have been '("").

@nicolasstucki nicolasstucki changed the title Macros: Incorrect error for string lifting Macros: Imprecise error for string lifting Dec 7, 2018
@allanrenucci
Copy link
Contributor

This is confusing. Why is "".toExpr invalid here?

@nicolasstucki
Copy link
Contributor

Because we need to interpret it. Which currently means interpretation of the annonimous class of the extension method.

@nicolasstucki
Copy link
Contributor

It is also invalid as parameters in a macro must be quoted or statically known values (literal constants or inline parameters)

liufengyun added a commit that referenced this issue Jul 11, 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

3 participants