如何检查WeakTypeTag
或Type
表示具体类型?这在宏中特别有用,当用户给出的类型不具体时,我可以使用它来引发编译错误:
def macroMethod[T]: Unit = macro macroMethod_impl[T]
def macroMethod_impl[T: c.WeakTypeTag](c: Context): c.Expr[Unit] = {
import c.universe._
def isConcrete(tpe: Type) = ???
if(!isConcrete(weakTypeOf[T])) {
c.error(c.enclosingPosition, "You must provide concrete type.")
}
c.literalUnit
}