title: Macro to map "items" to their type parameterized "containers" -- large compiler error
body: <p>Suppose I have a trait for "items" and another trait for "containers" of those items:</p>
  
  <pre><code>sealed trait Item
  case class Marble() extends Item
  case class Book() extends Item
  
  sealed trait Container[Item]
  case object Pouch extends Container[Marble]
  case object Shelf extends Container[Book]
  </code></pre>
  
  <p>Using the type information above, I'd like to construct a map like so via a macro and some runtime reflection:</p>
  
  <pre><code>// Map(classOf[Marble] -&gt; Pouch, classOf[Book] -&gt; Shelf)
  val itemToContainer = typeParamMap[Container[_], Item](Pouch, Shelf)
  </code></pre>
  
  <p>Here's my attempt, which compiles fine, and works in an intermediate form that just returns the list of TypeTags:</p>
  
  <pre><code>object Macros {
    def getTag[T](implicit ttag: ru.TypeTag[T]) = ttag
  
    def getBaseParam(child: ru.Type, base: ru.Symbol, paramBase: ru.Symbol) =
      child.baseType(base)
        .find(_.baseClasses.contains(paramBase))
        .get
        .typeSymbol
        .asClass // TODO how to get java.lang.Class from here?
  
    def typeParamMapImpl[B, P](c: Context)(children: c.Expr[B]*)(baseTag: c.Expr[ru.WeakTypeTag[B]], paramTag: c.Expr[ru.WeakTypeTag[P]]) = {
      import c.universe._
  
      val getTagTree = Select(Ident(newTermName("Macros")), "getTag")
      val typeTags = c.Expr[List[ru.TypeTag[_]]](Apply(reify(List).tree, children.map( t =&gt;
        c.Expr(TypeApply(getTagTree, List(t.tree))).tree
      ).toList))
  
      reify {
        typeTags.splice.map { child =&gt;
          getBaseParam(child.tpe, baseTag.splice.tpe.typeSymbol, paramTag.splice.tpe.typeSymbol) -&gt; child.tpe
        }.toMap
      }
    }
  
    def typeParamMap[B, P](children: B*)(implicit baseTag: ru.WeakTypeTag[B], paramTag: ru.WeakTypeTag[P]) = macro Macros.typeParamMapImpl[B, P]
  }
  </code></pre>
  
  <p>However when I try to compile with an invocation of this, I get a huge compiler error: <a href="https://gist.github.com/4647812" rel="nofollow">https://gist.github.com/4647812</a></p>
  
  <p>Can anyone spot the problem, or suggest a better way of going about this?</p>
  
  <p>Thanks!</p>