0) } object Je...">

"too few argument lists to call the macro"

Given the following code:

case class JetDim(dimension: Int) {
  require(dimension > 0)
}

object JetDim {
  def build(dimension: Int): Int = macro JetDimMacro.apply
}

      

and the macro that it calls:

def apply(dimension: Int): Int = macro applyImpl

def applyImpl(c: Context)(dimension: c.Expr[Int]): c.Expr[Int] = ...

      

I am getting this compile time error:

[error]  too few argument lists for macro invocation
[error]  def build(dimension: Int): Int = macro JetDimMacro.apply

      

Why?

+1


source to share


1 answer


The keyword macro

takes a method, which must have a parameter Context

as its first parameter list (and then as many arguments as desired Expr

in subsequent lists). In JetDim

you provide a macro

method that itself has a macro implementation. It's just not valid syntax - you can't "nest" macro

like this. You need to either call JetDimMacro.apply

directly (like a normal method call) on JetDim.build

, or use macro JetDimMacro.applyImpl

(which is more likely what you want).



+2


source







All Articles