错误报告:代码合同引起的CA1804假阳性1.4.60317.12(转载) [英] Bug Report: False positive CA1804 Caused by Code Contracts 1.4.60317.12 (Reproduced)

查看:63
本文介绍了错误报告:代码合同引起的CA1804假阳性1.4.60317.12(转载)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自升级到Code Contracts 1.4.60317.12后,我收到几个误报,代码分析警告CA1804(删除未使用的当地人)。

Since upgrading to Code Contracts 1.4.60317.12 I'm getting several false positives for Code Analysis warning CA1804 (Remove Unused Locals).

重新发布:

*创建一个类库。

*启用代码分析并确保已启用代码分析警告CA1804(删除未使用的本地)。

* Turn on Code Analysis and ensure that you have enabled Code Analysis warning CA1804 (Remove Unused Locals).

*启用代码合约,使用以下设置:

* Turn on Code Contracts, with the following settings:

   标准合同要求

    Standard Contract Requires

   执行运行时合同检查=完整

    Perform Runtime Contract Checking = Full

   所有其他设置=默认值

    All other settings = default values

添加包含以下方法的静态类:

Add a static class containing the following method:

        public static IEnumerable<T> Of<T>(T item)
        {
            Contract.Ensures(Contract.Result<IEnumerable<T>>() != null);
            yield return item;
        }

如果我将其编译为DEBUG版本,我会收到以下代码分析警告:

If I compile this as a DEBUG build, I get the following Code Analysis warning:

CA1804  删除未使用的本地语

'Program.Of< T>(T)'声明一个变量''<> 1__state',类型为'int',从未使用过或者仅被分配到。使用此变量或将其删除。

CA1804 Remove unused locals
'Program.Of<T>(T)' declares a variable, '<>1__state', of type 'int', which is never used or is only assigned to. Use this variable or remove it.

RELEASE版本不会发生这种情况。以前版本的代码合同也不会发生这种情况。

This does NOT happen with a RELEASE build. It also does not happen with the previous version of Code Contracts.

平台:Windows 7 x64

Platform: Windows 7 x64

IDE:Visual Studio 2012 + Update 1

IDE: Visual Studio 2012 + Update 1

环境:四核Intel,16GB RAM。

Environment: Quad core Intel, 16GB RAM.

推荐答案

谢谢,我们也可以重复这一点。我为这次回归道歉。

Thanks, we can repro this too. I apologize for this regression.


这篇关于错误报告:代码合同引起的CA1804假阳性1.4.60317.12(转载)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆