dotnet/roslyn

IDE0059 incorrectly suggests removal of used variable

Open

#64,044 创建于 2022年9月15日

在 GitHub 查看
 (2 评论) (1 反应) (0 负责人)C# (4,257 fork)batch import
Area-IDEBugFeature - IDE0059help wanted

仓库指标

Star
 (20,414 star)
PR 合并指标
 (平均合并 6天 17小时) (30 天内合并 256 个 PR)

描述

Version Used: Microsoft Visual Studio Enterprise 2022 (64-bit) - Current Version 17.3.3, TargetFramework net6.0

Steps to Reproduce:

int count;
try
{
    if (0 == 1) { } // comment out to "fix" suggestion
    Console.WriteLine(); // comment out to "fix" suggestion
}
finally
{
    count = 3;
}

if (count == 0) { }

Expected Behavior: Do not delete my variable assignment.

Actual Behavior: Wants to break my code. If I follow the suggestion it removes the variable. It can alter the code semantics by deleting necessary assignments. In my example the compiler will error because count was not assigned but it could be more subtle. If you comment out either statement in the try block, the suggestion will disappear.

贡献者指南