Overload resolution simplification

Neal Gafter neal at gafter.com
Wed Aug 14 12:19:23 PDT 2013


Maurizio-

Eric is right: the body of a called method is never involved in overload
resolution.  But that has nothing to do with lambdas.

-Neal


On Wed, Aug 14, 2013 at 3:29 AM, Maurizio Cimadamore <
maurizio.cimadamore at oracle.com> wrote:

> On 14/08/13 10:57, Maurizio Cimadamore wrote:
>
>> but it would seems that C# can use the target-type information _ahead_ of
>> overload resolution to perform inference, thus being able to reject
>> applicable candidates based on return mismatch (which Java cannot do).
>>
> This is incorrect - I found this [1] which clearly states (Eric Lippert)
> that by design, in C# type information flows from argument types outwards,
> not the other way around. This means that several examples discussed in
> this mailing list wouldn't work in C# too, especially the ones around
> Comparator.comparing - in that case in fact, the only way to type-check the
> lambda is to instantiate the formal parameter of the method with the
> information that's available from the target-type context. Java won't do it
> because that would break the invariant that overload selection should not
> depend on target type. It seems like C# has a similar (sensible)
> restriction.
>
> [1] - http://stackoverflow.com/**questions/3203643/generic-**
> methods-in-net-cannot-have-**their-return-types-inferred-**why<http://stackoverflow.com/questions/3203643/generic-methods-in-net-cannot-have-their-return-types-inferred-why>
>
> Maurizio
>


More information about the lambda-spec-observers mailing list