These are chat archives for Microsoft/CodeContracts

25th
Jul 2015
Sergey Teplyakov
@SergeyTeplyakov
Jul 25 2015 00:52
@sharwell Maybe we should discuss #171 here first
I've looked at two suggestions that you've made in the PR, and I don't think we should add preconditions that's will contradict the implementation...
there is no official contracts for those classes and the only way we can tell is from implementation
Sam Harwell
@sharwell
Jul 25 2015 00:53
Technically it's not a contradiction, it's a restriction
I'm fine with not including them if people use them that way, but the documentation should be updated to define the behavior for these cases because it doesn't follow the generally expected behavior of an IEnumerable<T>
Sergey Teplyakov
@SergeyTeplyakov
Jul 25 2015 00:55
From theoreticall point of view, we can't use stronger preconditions:)
You're absolutely right, but adding such contracts will show additional false positives. CCCheck will tell that the code is not correct, but it is correct from implementation perspective.
We should not invent preconditions!
If something is marked as 'can be null` we should leave as is.
Sam Harwell
@sharwell
Jul 25 2015 00:57
I really don't think your reply on SwitchExpression.Update is correct
The line after ToReadOnly is a requirement that it not be empty
null → empty → exception
Sergey Teplyakov
@SergeyTeplyakov
Jul 25 2015 00:58
but that means that requires should be like that: Contract.Requires(seq != null && seq.Any())
Enumerable.Empty is just a buggy code in this case...
Sam Harwell
@sharwell
Jul 25 2015 00:58
That is a further restriction on what I said though. My statement (we can require cases not be null) is correct.
Sergey Teplyakov
@SergeyTeplyakov
Jul 25 2015 00:59
More over: following precondition should be added: Contract.Requires(Contract.ForAll(cases, c => c != null))
sorry, I've missed that
But in this case we should add appropriate precondition if we figured them out:)
Sam Harwell
@sharwell
Jul 25 2015 01:00
You can add that comment with the stronger conditions
Sergey Teplyakov
@SergeyTeplyakov
Jul 25 2015 01:01
yep, added. Thanks!
Sam Harwell
@sharwell
Jul 25 2015 01:24
Expressions.cs is huge
Sergey Teplyakov
@SergeyTeplyakov
Jul 25 2015 01:31
Yeah:)
Sam Harwell
@sharwell
Jul 25 2015 01:32
I opened it in a separate viewer