“too few argument lists for macro invocation”

元气小坏坏 提交于 2019-12-13 01:27:45

问题


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'm getting this compile-time error:

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

Why?


回答1:


The macro keyword takes a method that should have a Context parameter as its first parameter list (and then however many Expr arguments in subsequent lists). In JetDim you're giving macro a method that itself has a macro implementation. This just isn't valid syntax—you can't "nest" macro like this. You'll need to either call JetDimMacro.apply directly (as a normal method call) in JetDim.build, or use macro JetDimMacro.applyImpl (which is more likely what you want).



来源:https://stackoverflow.com/questions/29948004/too-few-argument-lists-for-macro-invocation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!