mirror of
https://github.com/github/codeql.git
synced 2026-04-27 09:45:15 +02:00
Merge pull request #2568 from calumgrant/cs/assignment-to-_
C#: Remove FP in useless assignment to _
This commit is contained in:
@@ -13,6 +13,7 @@ The following changes in version 1.24 affect C# analysis in all applications.
|
||||
|
||||
| **Query** | **Expected impact** | **Change** |
|
||||
|------------------------------|------------------------|-----------------------------------|
|
||||
| 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. |
|
||||
|
||||
## Removal of old queries
|
||||
|
||||
|
||||
@@ -83,8 +83,10 @@ class RelevantDefinition extends AssignableDefinition {
|
||||
//or
|
||||
//this.(AssignableDefinitions::OutRefDefinition).getTargetAccess().isOutArgument()
|
||||
this.(AssignableDefinitions::LocalVariableDefinition).getDeclaration() = any(LocalVariableDeclExpr lvde |
|
||||
lvde = any(SpecificCatchClause scc).getVariableDeclExpr() or
|
||||
lvde = any(ForeachStmt fs).getVariableDeclExpr()
|
||||
lvde = any(SpecificCatchClause scc).getVariableDeclExpr()
|
||||
or
|
||||
lvde = any(ForeachStmt fs).getVariableDeclExpr() and
|
||||
not lvde.getName() = "_"
|
||||
)
|
||||
or
|
||||
this instanceof AssignableDefinitions::PatternDefinition
|
||||
|
||||
@@ -259,7 +259,7 @@ public class Captured
|
||||
fn(() =>
|
||||
{
|
||||
var x = y; // BAD: Dead store in lambda
|
||||
return 0;
|
||||
return 0;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -425,3 +425,14 @@ class Finally
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
public static class AnonymousVariable
|
||||
{
|
||||
public static int Count<T>(this IEnumerable<T> items)
|
||||
{
|
||||
int count = 0;
|
||||
foreach (var _ in items) // GOOD
|
||||
count++;
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user