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
{{ message }}
This repository was archived by the owner on Jul 15, 2023. It is now read-only.
class Program
{
static Task<T> Foo<T>(T source)
where T : class
{
Contract.Ensures(Contract.Result<T>() != null);
return Task.FromResult(source);
}
static void Main(string[] args)
{
Foo(new object()).Wait();
}
}
leads to BadImageFormatException, while this one - does not:
static async Task<T> Foo<T>(T source)
where T : class
{
Contract.Ensures(Contract.Result<T>() != null);
return await Task.FromResult(source);
}
The only difference is awaiting the task in the second sample, which is totally unnecessary here.
It seems to me, that using Contract.Result<T>() in Foo is logically incorrect too .We're not awaiting a task result, we're just returning a task. Though, BadImageFormatException shouldn't be thrown, and I need a way to point CC to check task result here.