Skip to content

Disallow inline macro with statements before the splice #4151

Closed
@nicolasstucki

Description

@nicolasstucki

We should disallow statements before the call to the top level splice of the macro such as

inline def foo: Int = {
  println("foo") // should be an error
  ~impl()
}
def impl(): Expr[Int] = '(1)

The correct way to inline the statements would be to put them in the quoted code itself

inline def foo: Int = ~impl()
def impl(): Expr[Int] = '{
  println("foo")
  1
}

or

inline def foo: Int = ~{ 
  '{ 
    println("foo")
    ~impl()
  }
}
def impl(): Expr[Int] = '(1)

The motivation for this is to always know statically all the arguments of the top level splice. These argouments are the arguments of the inline macro.

It is not enough to check if the rhs is a splice as the following code should work and may generate a block without statements

inline def foo: Int = {
  ~impl()
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions