I guess you want something like this:
val innerType = weakTypeOf[T] match {
case r: TypeRef => r.args.head
case _ => c.abort(c.enclosingPosition, "call this method with known type parameter only.")
}
Note that WeakTypeTag
could be not a TypeRef
.
This method will fail on None.type
. To make it work on subtypes (like None.type
) you should use a method baseType
like this:
val innerType = weakTypeOf[T].baseType(typeOf[Option[_]].typeSymbol) match {
case TypeRef(_, _, targ :: Nil) => targ
case NoType => c.abort(...)
}