Is it possible to determine the type of a pattern variable in a Scala macro? -
as part of macro need inspect patterns of case definitions.
is there way determine type of pattern variable, or whole pattern?
consider polymorphic class data
, , macro uses transformer inspect , transform patterns on data
values:
case class data[a](x: string, data: a) def macroimpl(c: context)(...) = { val transformer = new transformer { override def transformcasedefs(trees: list[casedef]) = trees map { case casedef(pattern, guard , body) => pattern match { case pq"data($string, $data)" => { // type of $data, i.e., how // type parameter instantiated? ... } } } } ... transformer.transform(...) }
is there way determine type of pattern variable $data, i.e., way determine how type parameter has been instantiated?
another question discusses problem trees of values , suggests use of c.typecheck
function. unfortunately, doesn't seem work patterns, since typecheck
method throws typecheckexception
when applied pattern tree of example above.
Comments
Post a Comment