You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The lambda improvements proposal includes inferring delegate types for lambdas and method groups, creating the possibility of breaking changes in overload resolution.
Example 1
Two overloads in the default method group M, one with a generic parameter type, the other with a delegate type parameter. In C#9, M(F) binds to M(Action<string> a).
If a delegate type is inferred for F of Action<object>, overload resolution will bind to the generic overload M<Action<object>>(Action<object> t) instead.
Two overloads in the method group c.M, one with an object type parameter on the containing type, the other with a delegate type parameter as an extension method. In C#9, the calls to c.M(expr) bind to the extension method.
If delegate types are inferred for the method group and lambda expression, those expressions are implicitly convertible to object and overload resolution will bind the calls to the overload on the containing type instead.
Prefer binding lambda or method group arguments using the target type (the parameter type) rather than the inferred delegate type of the lambda expression or method group.
If extension methods should be considered, and binding of the method group from the containing type or any inner extension method scope used the inferred type for lambda or method group arguments, continue searching outer extension method scopes for an overload that binds using the parameter type.
The text was updated successfully, but these errors were encountered:
The lambda improvements proposal includes inferring delegate types for lambdas and method groups, creating the possibility of breaking changes in overload resolution.
Example 1
Two overloads in the default method group
M
, one with a generic parameter type, the other with a delegate type parameter. In C#9,M(F)
binds toM(Action<string> a)
.If a delegate type is inferred for
F
ofAction<object>
, overload resolution will bind to the generic overloadM<Action<object>>(Action<object> t)
instead.See sharplab.io
Example 2
Two overloads in the method group
c.M
, one with anobject
type parameter on the containing type, the other with a delegate type parameter as an extension method. In C#9, the calls toc.M(expr)
bind to the extension method.If delegate types are inferred for the method group and lambda expression, those expressions are implicitly convertible to
object
and overload resolution will bind the calls to the overload on the containing type instead.See sharplab.io
Possible solution
The text was updated successfully, but these errors were encountered: