public void MethodA(string input)
{
Contract.Requires(input != null);
string extended = input + ' ';
Contract.Assume(extended[extended.Length - 1] == ' '); // warning : CodeContracts: requires unproven: 0 <= index
MethodB(extended);
Contract.Assert(extended.Length > 0);
Contract.Assert(extended[extended.Length - 1] == ' '); // warning : CodeContracts: assert unproven
}
public void MethodB(string input)
{
Contract.Requires(input != null);
Contract.Requires(input.Length > 0);
Contract.Requires(input[input.Length - 1] == ' ');
////Contract.Ensures(input[input.Length - 1] == ' '); // this line can prove the assert in MethodA ?!?
}
I believe the first warning may be due to a missing postcondition on string operator +(string, char).
Converting that first Assume into an Assert makes the Assert unproven. I'm not sure about that one...
But the second warning should not be there. In fact, if you add the postcondition in MethodB, that Assert is considered proven !?!