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
method groups to contribute to output type inference
infering bounds for the Ui type parameters in C<U1 ... Uk> when given a C<V1...Vk> and C is a class, struct, interface or delegate type.
But they don't allow method groups to contribute to bounds.
Test(IsEven); // Error CS0411 The type arguments for method 'Program.Test<T>(Func<T, bool>)' cannot be inferred from the usage. Try specifying the type arguments explicitly.
partial class Program
{
public static bool IsEven(int x) => x % 2 == 0;
public static void Test<T>(Func<T, bool> predicate) { }
}
An explicit parameter type inference is made from an expression Eto a type T in the following way:
If E is an explicitly typed anonymous function *or method group with a unique signature with parameter types U₁...Uᵥ and T is a delegate type or expression tree type with parameter types V₁...Vᵥ then for each Uᵢ an exact inference is made fromUᵢto the corresponding Vᵢ.
Follow-ups:
we need to confirm this was not left out intentionally from the "lambda improvements" work
outline and review any potential breaking changes
Relates to issue for method groups contributing to method type inference: #129
Type inference using method group natural type
Summary
It allows the natural type of a method group to contribute to method type inference
Context on method type inference
The current type inference rules allow
Ui
type parameters inC<U1 ... Uk>
when given aC<V1...Vk>
andC
is a class, struct, interface or delegate type.But they don't allow method groups to contribute to bounds.
Type inference
We modify the explicit parameter type inference rules to not just apply to explicitly-typed lambdas, but also to method groups:
An explicit parameter type inference is made from an expression
E
to a typeT
in the following way:E
is an explicitly typed anonymous function *or method group with a unique signature with parameter typesU₁...Uᵥ
andT
is a delegate type or expression tree type with parameter typesV₁...Vᵥ
then for eachUᵢ
an exact inference is made fromUᵢ
to the correspondingVᵢ
.Follow-ups:
Relates to issue for method groups contributing to method type inference: #129
LDM Discussions
The text was updated successfully, but these errors were encountered: