我在回答this question。如何将一个无参数构造函数添加到具有宏注解的Scala案例类中?
而是写的:
case class Person(name: String, age: Int) {
def this() = this("",1)
}
我想我会用宏注释从展开:
@Annotation
case class Person(name: String, age: Int)
所以我尝试添加新的构造函数作为一个纯老DefDef
使用quasiquotes在宏注释的impl中,如:
val newCtor = q"""def this() = this("", 1)"""
val newBody = body :+ newCtor
q"$mods class $name[..$tparams](..$first)(...$rest) extends ..$parents { $self => ..$newBody }"
但是那个返回ns错误:called constructor's definition must precede calling constructor's definition
有没有办法解决这个问题?我错过了什么?
感谢您抽空看看, -Julian
唉,我使用天堂2.0.0-M6为2.10.3。 [Here](https://github.com/julianpeeters/macro-annotation-example/tree/no-args)是一个最小的可运行示例。并且[这里](https://gist.github.com/julianpeeters/9888898)是M4中的错误。 –
哦,我明白了。所以我们在这里有两个错误。一个由M6固定,另一个依然存在。 –
https://github.com/julianpeeters/macro-annotation-example/pull/1 –