File tree Expand file tree Collapse file tree 3 files changed +17
-3
lines changed
test/query-tests/Dead Code/DeadStoreOfLocal Expand file tree Collapse file tree 3 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ The following changes in version 1.24 affect C# analysis in all applications.
1313
1414| ** Query** | ** Expected impact** | ** Change** |
1515| ------------------------------| ------------------------| -----------------------------------|
16+ | Useless assignment to local variable (` cs/useless-assignment-to-local ` ) | Fewer false positive results | Results have been removed when the variable is named ` _ ` in a ` foreach ` statement. |
1617
1718## Removal of old queries
1819
Original file line number Diff line number Diff line change @@ -83,8 +83,10 @@ class RelevantDefinition extends AssignableDefinition {
8383 //or
8484 //this.(AssignableDefinitions::OutRefDefinition).getTargetAccess().isOutArgument()
8585 this .( AssignableDefinitions:: LocalVariableDefinition ) .getDeclaration ( ) = any ( LocalVariableDeclExpr lvde |
86- lvde = any ( SpecificCatchClause scc ) .getVariableDeclExpr ( ) or
87- lvde = any ( ForeachStmt fs ) .getVariableDeclExpr ( )
86+ lvde = any ( SpecificCatchClause scc ) .getVariableDeclExpr ( )
87+ or
88+ lvde = any ( ForeachStmt fs ) .getVariableDeclExpr ( ) and
89+ not lvde .getName ( ) = "_"
8890 )
8991 or
9092 this instanceof AssignableDefinitions:: PatternDefinition
Original file line number Diff line number Diff line change @@ -259,7 +259,7 @@ void M7()
259259 fn ( ( ) =>
260260 {
261261 var x = y ; // BAD: Dead store in lambda
262- return 0 ;
262+ return 0 ;
263263 } ) ;
264264 }
265265
@@ -425,3 +425,14 @@ int M(bool b)
425425 return i ;
426426 }
427427}
428+
429+ public static class AnonymousVariable
430+ {
431+ public static int Count < T > ( this IEnumerable < T > items )
432+ {
433+ int count = 0 ;
434+ foreach ( var _ in items ) // GOOD
435+ count ++ ;
436+ return count ;
437+ }
438+ }
You can’t perform that action at this time.
0 commit comments