locked
[BUG REPORT] False Code Analysis: CA1804 with Code Contracts 1.5.60813.10 RRS feed

  • Question

  • We are unable to use the latest version of Code Contracts (1.5.60813.10) due to a false positive Code Analysis warning CA1804 which is occurring in a lot of our assemblies.

    I have managed to find a minimal reproduction.

    TO REPRODUCE THE ERROR:

    Firstly create an assembly with Code Contracts turned on and Code Analysis warning 1804 enabled.

    Then add the following class:

    public class Bug
    {
        public void DemonstrateBug(string x)
        {
            Contract.Requires(x != null);
    
            // Bug does not occur if you remove this extra scope (the braces)
            {
                test(() => Console.WriteLine(test1()));
            }
        }
    
        private string test1() // Bug does not occur if this method is static.
        {
            return null;
        }
    
        private static void test(Action a)
        {
            a();
        }
    }

    When you compile this, you get the following spurious Code Analysis warning/error:

    CA1804 Remove unused locals
    'Bug.DemonstrateBug(string)' declares a variable, 'temp', of type 'Action', which is never used or is only assigned to. Use this variable or remove it.


    Thursday, August 15, 2013 1:29 PM

Answers

  • We put out a new release 1.5.60911.10 that should fix this issue.


    Cheers, -MaF (Manuel Fahndrich)

    Thursday, September 12, 2013 3:14 PM

All replies

  • Confirm. The same thing at our projects.
    Monday, August 26, 2013 10:17 AM
  • Same over here, after upgrading an extra 70+ warnings for CA1804.

    Reverted to an older version (1.60221.11) for now.

    Monday, August 26, 2013 12:32 PM
  • Yes, unfortunately this version is unusable.
    Wednesday, September 4, 2013 12:31 PM
  • Sorry, yes, this is a problem we know and fixed. I will try to push out a release this week to fix this.


    Cheers, -MaF (Manuel Fahndrich)

    Wednesday, September 11, 2013 3:23 PM
  • We put out a new release 1.5.60911.10 that should fix this issue.


    Cheers, -MaF (Manuel Fahndrich)

    Thursday, September 12, 2013 3:14 PM
  • Thanks, I can confirm that 1.5.60911.10 has resolved this issue. :)

    Monday, September 16, 2013 12:15 PM