Is there a way to use an argument to a macro in a pattern match? I would like to do this:
def extr(X:AnyRef) = macro extrImpl
def extrImpl(c:Context)(X:c.Expr[AnyRef]):c.Expr[AnyRef] = {
import c.universe._
val tree = reify {
new {
def unapply(x:String):Option[String] = x match {
case X.splice => Some(x) //error
case _ => None
}
}
}.tree
c.Expr(c.typeCheck(tree))
}
But unfortunately the compiler says "stable identifier required, but X.splice found". Normally, one would solve this by assigning to a val first, such as:
val XX = X.splice
But of course that doesn't work with splice either.
Unfortunately it's not possible right now (and won't be possible in 2.10.0-final), but we have something in works that might help in subsequent point releases :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With