I’m not sure if this is possible yet, but if macro annotations are allowed to fill in methods of a trait
, I think I’ve come around to the idea that you should avoid generating declarations that typer
relies on. That is, val hola = ${MyMacro.dothis(false)}
is great, as is
trait HasSomeMethod {
def classNameAndMethodCount(): (String, Int)
}
@fillInHasSomeMethod
class Foo extends HasSomeMethod {
def method1(): Int = 5
def method2(): Boolean = false
// `@fillInHasSomeMethod quietly generates
// def classNameAndMethodCount(): (String, Int) = ("HasSomeMethod", 2)
}
Tooling might still get a little confused about where to bring you for the definition of Foo. classNameAndMethodCount, but it’s no longer totally magical – it could just bring you to the trait.