Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

CodeContracts doesn't detect value is mutated by lambda method. #469

Open
daiplusplus opened this issue Nov 21, 2016 · 0 comments
Open

CodeContracts doesn't detect value is mutated by lambda method. #469

daiplusplus opened this issue Nov 21, 2016 · 0 comments

Comments

@daiplusplus
Copy link

daiplusplus commented Nov 21, 2016

I have code in a function which does this:

Int32 count = 0;
Parallel.ForEach( foos, (foo) =>
{
    lock( _lock )
    {
        // do stuff
        count++;
    }
}
Int32 x = GetX();
if( 0 <= x && x < count ) {
    // more stuff
}

I get this warning:

CodeContracts warning: The Boolean condition x < 0 always evaluates to a constant value. If it (or its negation) appear in the source code, you may have some dead code or a redundant check.

The expression 0 <= x && x < count has a purple squiggle underline.

If I change the Parallel.ForEach to a regular foreach then I don't get the warning.

I'm using Code Contracts 1.9.10714.2 in VS2015 Enterprise Update 3.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant