Scala Def Macros - How do I get the parameterized type member of a symbol?

268 views Asked by At

I'm trying to get the parameterized type of a member on a symbol in a MACRO context. I only have a symbol available (can't use weakTypeOf[List[Blah]]) because I am iterating over a bunch of classes.

val meWantArg = classSymbol.member("paramList": TermName).typeSignature

returns...

=> List[IWantThis]

How do I get IWantThis Type object???

I've tried:

meWantArg.typeSymbol.asType.typeParams //returns List(type A)

I've tried extraction:

TypeRef(_,_,args) = meWantArg //returns ()

Keep in mind, I am using the 2.10.2 macro plugin.

1

There are 1 answers

0
gourlaysama On BEST ANSWER

I am guessing from => IWantThis that paramList is not a val but an arity-0 method without parentheses:

def paramList: List[IWantThis] = ???

If so, the member is a method type, and you have to get the return type of the method before extracting arguments from it:

val meWantArg = classSymbol.member("paramList": TermName).asMethod.returnType
val TypeRef(_,_,args) = meWantArg