Consider a scenario where we have a generic method that should be able to return a null-reference of T, thus T has to be nullable.
Kind of like this:
public static T GetNullableTypeTest<T>()
{
Contract.Requires(!typeof(T).IsValueType || Nullable.GetUnderlyingType(typeof(T)) != null);
return (T)(object)null;
}
CC doesn't seem to understand at all what we are trying to do, it complains about unboxing null and method calls results in an "unproven" warning.
Are there any ways to enforce this constraint in Code Contracts?