scala/scala — pull request #3995 by retronym (2014-09-22 04:45:14+00:00)
Title: SI-8267 Avoid existentials after polymorphic overload resolution

... which can be introduced by `memberType` for methods
with methods dependent on class type parameters.

Usually these are skolemized out of existence, but when
we carry through multiple overloaded alternatives and deferred
the call to `memberType`, this wasn't happening.

This commit calls `adapt` on function tree after polymorphic
overload resolution has run. This is analagous to `doTypedApply`:

```scala
inferMethodAlternative(fun, undetparams, argTpes, pt)
doTypedApply(tree, adapt(fun, mode.forFunMode, WildcardType), args1, mode, pt)
```

This REPL transcript might further illustrate the problem.

```
scala> class Bippy { trait Foo[A] }
defined class Bippy

scala> final class RichBippy[C <: Bippy with Singleton](val c1: C) {
| def g[A](x: A)(ev: c1.Foo[A]): Int = 2
| }
defined class RichBippy

scala> :power
** Power User mode enabled - BEEP WHIR GYVE **
** :phase has been set to 'typer'. **
** scala.tools.nsc._ has been imported **
** global._, definitions._ also imported **
** Try :help, :vals, power. **

scala> val g = typeOf[RichBippy[_]].member(TermName("g"))
g: $r.intp.global.Symbol = method g

scala> val c = new Bippy
c: Bippy = Bippy@92e2c93

scala> val memberType = typeOf[RichBippy[c.type]].memberType(g)
memberType: $r.intp.global.Type = ([A](x: A)(ev: _7.c1.Foo[A])Int) forSome { val _7: RichBippy[c.type] }

scala> val tree = Ident(TermName("dummy")).setType(memberType)
tree: $r.intp.global.Ident = dummy

scala> def adaptExprWildcard(t: Tree) = {
| type HasAdapt = { def adapt(t: Tree, mode: Int, pt: Type, original: Tree) }
| typer.asInstanceOf[HasAdapt].adapt(t, Mode.EXPRmode.bits, WildcardType, EmptyTree)
| }
warning: there was one feature warning; re-run with -feature for details
adaptExprWildcard: (t: $r.intp.global.Tree)Unit

scala> adaptExprWildcard(tree)

scala> tree.tpe
res1: $r.intp.global.Type = [A](x: A)(ev: _7.c1.Foo[A])Int

scala> memberType.skolemizeExistential
res2: $r.intp.global.Type = [A](x: A)(ev: _7.c1.Foo[A])Int
```

Review by @lrytz / @adriaanm