Why can't the correct overload to be called be inferred on the line marked // Compiler Error
in the code below when the type is correctly inferred in all the other cases?
public static class Code {
private static void Main() {
OverloadedMethod<string>(() => new Wrapper<string>()); // OK
OverloadedMethod<string>(() => MethodReturningWrappedString()); // OK
OverloadedMethod<string>((Func<Wrapper<string>>)MethodReturningWrappedString); // OK
OverloadedMethod<string>(MethodReturningWrappedString); // Compiler Error
}
public static Wrapper<string> MethodReturningWrappedString() {
return new Wrapper<string>();
}
public static void OverloadedMethod<T>(Func<Wrapper<T>> func) where T : class {
}
public static void OverloadedMethod<T>(Func<T> func) where T : class {
}
public struct Wrapper<T> where T : class {
}
}
Here's the compiler error:
The call is ambiguous between the following methods or properties:
'Namespace.Code.OverloadedMethod<string>(System.Func<Namespace.Code.Wrapper<string>>)'
and 'Namespace.Code.OverloadedMethod<string>(System.Func<string>)'