Reputation: 1339
I've created a simple macro that generates compiler warnings (or errors) if the current date is passed the FIXME (or TODO) date specified.
The macro implementation (see here) for Scala 2.10.4 used c.Expr[Any]
return type, in 2.11.0 it is a whitebox macro that returns c.Tree
.
In either case returning c.Expr[Any](EmptyTree)
or EmptyTree
respectively returns a value. Supposing the following invocation of the macro,
def hi() {
FIXME("2073/04/10: This will abort compilation if not fixed by 2073/04/10")
println("hi")
}
Compilation generates the following,
def hi(): Unit = {
(<empty>: scala.runtime.BoxedUnit);
scala.this.Predef.println("hi")
};
at the macro call site. Is it possible to generate the following instead:
def hi(): Unit = {
scala.this.Predef.println("hi")
};
Upvotes: 0
Views: 323
Reputation: 39577
You might consider making the fixable block an argument to the macro:
def hi = FIXME("...") { println(...) }
Compare what the compiler does with elidable code: it elides to a "zero" value, not an empty tree.
https://github.com/scala/scala/blob/2.10.x/src/compiler/scala/tools/nsc/transform/UnCurry.scala#L515
You might also consider a macro annotation.
Upvotes: 2