scala/scala — pull request #3331 by retronym (2014-01-07 13:09:20+00:00)
Title: SI-8120 Avoid tree sharing when typechecking patmat anon functions

When typechecking an empty selector `Match` corresponding to:

{ case ... => ... }: (A => B)

We wrap it in a `Function` and typecheck:

(x$1 => x$1 match { case ... => ... })

Local symbols in this expression (representing values bound by
the pattern, or just definitions in the body or guard) are then
owned by the anonymous function's symbol.

However, if we ever discard this `Function` and start anew with
the empty selector match, as happens during the fallback to
use a view on the receiver in `tryTypedApply`, we found that we
had mutated the cases of the original tree, and allowed orphaned
local symbols to escape into the compiler pipeline.

This commit uses duplicated trees for the the cases in the synthetic
`Match` to avoid this problem.

Review by @adriaanm @xeno-by