0

I'm trying to write a generic macro in which I can grab any trees that match foo.bar, but only where foo is a Foo. I only need to look inside the enclosing class where the macro is called. So far I have this:

def getFooTrees[T](): Unit = macro getFooTrees_impl[T]

def getFooTrees_impl[T: c.WeakTypeTag](c: Context)(): c.Expr[Unit] = {
  import c.universe._

  val receiverType = implicitly[c.WeakTypeTag[T]].tpe
  val terms = c.enclosingClass  
    .filter { t =>
      t match {
        case Select(ident: Ident, name: TermName) if (??? == receiverType) =>
          true
        case _ =>
          false
      }
    }

  ...etc

}

How do I check the type of what ident refers to? Sorry if I'm totally lost in the woods here.

colinmarc
  • 2,421
  • 1
  • 22
  • 34

1 Answers1

0

Question probably long dormant but I had same problem

val ident: Ident = ... 
ident.tpe  // is null

val tree2 = c.typecheck(tree = ident,mode = c.TYPEmode)
tree2.tpe  // not null
Friggles
  • 634
  • 5
  • 7