Skip to content

Macros: Imprecise error for string lifting #5547

Closed
@liufengyun

Description

@liufengyun

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions