Skip to content

Commit

Permalink
#43. Fixed a bug that shows an error for inconsistent postcondition w…
Browse files Browse the repository at this point in the history
…ith tasks.
  • Loading branch information
SergeyTeplyakov committed Sep 11, 2014
1 parent 192e2df commit d79dec3
Showing 1 changed file with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,8 @@ private static string ErrorForIncompatibleEnsuresAndReturnType(IType methodResul
name = name.Replace("get_", "");
}

//string methodOrProperty = method.
return string.Format("Detected a call to Contract.Result<{0}>() in {1} '{2}' with return type '{3}'",
contractResult.GetClrName().ShortName, kind, name,
return string.Format("Detected a call to Result with '{0}' in {1} '{2}', should be '{3}'",
contractResult.GetPresentableName(CSharpLanguage.Instance), kind, name,
methodResult.GetPresentableName(CSharpLanguage.Instance));
}

Expand All @@ -84,8 +83,15 @@ private static bool MethodResultIsCompatibleWith(IType methodResult, IList<IDecl
contractResultTypes
.All(contractResult =>
{
// Result compatibility should consider tasks as an
var resultType = methodResult.IsGenericTask() ? methodResult.GetTaskUnderlyingType() : methodResult;
var resultType = methodResult;
var contractResultType = contractResult;

// Corner case: we can use Contract.Result<object>() for method that returns Task<string>!
if (resultType.IsGenericTask() && !contractResultType.IsGenericTask())
{
resultType = resultType.GetTaskUnderlyingType();
}

Contract.Assert(resultType != null);

return resultType.IsImplicitlyConvertibleTo(contractResult, rule);
Expand Down

0 comments on commit d79dec3

Please sign in to comment.