Improved custom builder lookup (solves #6)

This implementation uses auxilary macro.
I'm going to do some investigation about this behaviour.
My Current clues:
* I can't use auxilary macro directly, I need to weave a call to it in expanded code, because both macros live in the same compilation unit.
* annotation macro can't infer implicits vals from enclosing class scope (implicit val members), but we are able to traverse them manually. This means that problem does not lie in lack of enclosure members visibility. Maybe this behaviour is intended? From @ macros we can not only add new members but even whole companion objects. But then c.inferImplicitVal should not lookup any implicits, for the same reasons..
* based on previous clue - maybe compiler collect informations about implicits and scopes incrementally, during some typechecks or something like that? And static annotation expansions is done before phase in which compiler scan implicit vals within enclosure?

@xeno-by could you elaborate on this?

Dnia 30 wrz 2014 o godz. 10:41 Krzysztof Ciesielski <notifications@github.com> napisał(a):

> In macros/src/main/scala/com/softwaremill/macmemo/BuilderResolver.scala:
> 
> > +
> > +    def bringDefaultBuilder: Tree = {
> > +      val Literal(Constant(mfn: String)) = methodFullName.tree
> > +      val msg = s"Cannot find custom memo builder for '$mfn' - default builder will be used"
> > +      c.info(c.enclosingPosition, msg, false)
> > +      reify {
> > +        MemoCacheBuilder.guavaMemoCacheBuilder
> > +      }.tree
> > +    }
> > +
> > +    val builderTree = c.inferImplicitValue(typeOf[MemoCacheBuilder]) match {
> > +      case EmptyTree => bringDefaultBuilder
> > +      case foundBuilderTree => foundBuilderTree
> > +    }
> > +
> > +    c.Expr[MemoCacheBuilder](Block(List(), builderTree))
> So it seems that putting an auxiliary macro call inside a quasiquote makes c.inferImplicitValue() work well, where calling this from an annotation macro context doesn't work in all cases? That's really meta-meta :) But it looks kinda like a bug to me, or at least some weird incosistency I cannot understand...
> 
> —
> Reply to this email directly or view it on GitHub.