Hi
I have this code using generic and nullable:

// The first one is for class
public static TResult With<TInput, TResult>(this TInput o, 
          Func<TInput, TResult> evaluator)
    where TResult : class
    where TInput : class

// The second one is for struct (Nullable)
public static TResult With<TInput, TResult>(this Nullable<TInput> o, 
          Func<TInput, TResult> evaluator)
    where TResult : class
    where TInput : struct

Please note the TInput constraint, one is class, the other one is struct. Then I use them in:

string s;
int? i;

// ...

s.With(o => "");
i.With(o => ""); // Ambiguos method

It cause an Ambiguos error. But I also have the another pair:

public static TResult Return<TInput, TResult>(this TInput o,
          Func<TInput, TResult> evaluator, TResult failureValue)
    where TInput : class

public static TResult Return<TInput, TResult>(this Nullable<TInput> o,
          Func<TInput, TResult> evaluator, TResult failureValue)
    where TInput : struct

This one compiles successfully

string s;
int? i;

// ...

s.Return(o => 1, 0);
i.Return(o => i + 1, 0);

I got no clues why this happen. The first one seems Ok, but compiles error. The second one ('Return') should be error if the first one is, but compiles successfully. Did I miss something?

Edit
Report