scala/scala — pull request #2402 by retronym (2013-04-17 09:01:48+00:00)
Title: SI-7377 Fix retypechecking of patterns on case companion alias

Some ancient code in Typers switches from PATTERNmode to
EXPRmode when encountering `stableF(...)`. It just
typechecks `stableF` and discards the arguments.

To the best of Martin's recollection, this has something
to do with the need to typecheck patterns rather late in
the compiler, after `a.b` had been translated to `a.b()`
in `Uncurry`. I'm not able to motivate this with tests
using `-Xoldpatmat`; was there ever an even older pattern
matcher that ran *after* uncurry?

What changed in 2.10.1 to expose this wrinkle? dfbaaa17
fixed `TypeTree.copyAttrs` to copy the original tree.
During the descent of `ResetAttrs`, sub-trees are duplicated
before begin further transformed. Duplicating the `Match`
in 2.10.0 would forget that the original tree of:

pat = (a: Int)Foo(_)
`----------`
`- TypeTree((a: Int)Foo), with original Select(..., "FooAlias")

The retypechecking would operate on the `MethodType`, rather
than the `Select`, which was not considered a stable
application.

For 2.10.x, I've just tightened up the condition to only
hit this if `args` is empty. I'm almost certain that the code
can be removed altogether, and I'll do that when this is merged
to master.

Review by @paulp