scala/scala — pull request #1936 by retronym (2013-01-19 23:55:15+00:00)
Title: SI-6891 Fix value class + tailrec crasher.

rhs.substituteSymbols(old, new) leaves us with:

def loop#12225(x#12226: A#15491): scala#21.this.Unit#1615 =
loop#12225(x#12226)

In which the TermSymbol x#12226 has a stale info, pointing at
the A#7274, the class type parameter, rather than A#15491,
the corresponding type parameter of the synthetic backing
method.

I've improved `TreeSymSubstituter` to substitute not
only `Tree#{tpe, symbol}`, but also `DefTree#sym.info`.

The `pos` test that triggered the new code path are
listed here: https://gist.github.com/4575687

Scathing review, please, by @paulp + @adriaanm; it's a small patch, but touches some fundamental machinery.

Obviously I could limit the scope of the new code to the `substituteSymbols` calls in `ExtensionMethods`, but I don't see how its correctness is context sensitive.

It seems to me that `substituteSymbols` was a breeding ground for inconsistencies between `tree.tpe` and `tree.symbol.info`, and I'm at a loss as to why that doesn't cause more problems.

I'm currently trying to add a new check to `TreeCheckers` to find references to type parameters and method parameters (to start with, but what else?) that don't respect scoping, ie their owner chain doesn't include the owner of the parameter. This check would have diagnosed this bug other like it. Any and all suggestions for this line of investigation are most welcome. (Such checks will also be useful, nay, vital, for folks doing serious macro development)