Having a macro return a result of the correct type is fairly straightforward in 2.10.x,
import scala.language.experimental.macros
import scala.reflect.macros.Context
object fromName {
def apply(tpe: String): Any = macro fromNameImpl
def fromNameImpl(c: Context)(tpe: c.Expr[String]): c.Expr[Any] = {
import c.universe._
c.Expr(tpe.tree match {
case Literal(Constant("scala.Long")) => Literal(Constant(0L))
case Literal(Constant("java.lang.String")) => Literal(Constant(""))
case _ => Literal(Constant(()))
})
}
}
Sample REPL session,
scala> fromName("scala.Long")
res0: Long = 0
scala> fromName("java.lang.String")
res1: String = ""