dotnet/roslyn
IDE0059 incorrectly reported when a scoped variable is introduced.
開放
#41,905 建立於 2020年2月24日
Area-IDEBugFeature - IDE0059help wanted
倉庫指標
- 星標
- (20,414 顆星)
- PR 合併指標
- (平均合併 6天 17小時) (30 天內合併 256 個 PR)
描述
Version Used: 16.4.5
The following program triggers the bug. The code attempt += 1; is reported as unneeded which is incorrect.
using System;
class X
{
public X() { }
public X( int value ) => Value = value;
public int Value { get; set; }
}
class Program
{
static object Execute( X x ) => throw new NotImplementedException();
static object Run()
{
var attempt = 1;
while ( true )
{
try
{
var result = Execute( new X
{
Value = 1
} );
return result;
}
catch when ( attempt <= 5 ) { }
attempt += 1;
}
}
}
A few minor changes to the program eliminate the issue:
- Do not use property initializers for
new X()-Execute( new X( 1 ) ) - Do not introduce the local
resultand instead justreturn Execute...