scala/scala — pull request #3490 by retronym (2014-02-08 18:37:31+00:00)
Title: WIP SI-7459 Handle pattern binders used as prefixes in TypeTrees.

Match translation was incorrect for:

case t => new t.C
case D(t) => new d.C

We would end up with Types in TypeTrees referring to the wrong symbols, e.g:

// t7459a.scala
((x0$1: this.LM) => {
case val x1: this.LM = x0$1;
case4(){
matchEnd3(new tttt.Node[Any]())
};
matchEnd3(x: Any){
x
}

Or:
// t7459b.scala
((x0$1: CC) => {
case val x1: CC = x0$1;
case4(){
if (x1.ne(null))
matchEnd3(new tttt.Node[Any]())
else
case5()
};

This commit:

- Changes `bindSubPats` to traverse types, as well as terms,
in search of references to bound symbols
- Changes `Substitution` to reuse `Tree#substituteSymbols` rather
than the home-brew substitution from `Tree`s to `Tree`s, if the
`to` trees are all `Ident`s

I had to dance around the awkward handling of "swatches" (exception
handlers that can be implemented with JVM native type switches) by
duplicating trees to avoid seeing the results of `substituteSymbols`
in `caseDefs` after we abandon that approach if we detect the
patterns are too complex late in the game.

Review by @adriaanm

This one has been haunting us from a long time, and I finally
figured out the last 10% of my fix today. I'd like to get this into
2.11.0.