Skip to content

Commit 3db900b

Browse files
committed
C#: Remove false positive and update test output
C#: Mark results as GOOD
1 parent fd0225c commit 3db900b

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

csharp/ql/src/Dead Code/DeadStoreOfLocal.ql

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff 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

csharp/ql/test/query-tests/Dead Code/DeadStoreOfLocal/DeadStoreOfLocal.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ public static class AnonymousVariable
431431
public static int Count<T>(this IEnumerable<T> items)
432432
{
433433
int count = 0;
434-
foreach (var _ in items)
434+
foreach (var _ in items) // GOOD
435435
count++;
436436
return count;
437437
}

csharp/ql/test/query-tests/Dead Code/DeadStoreOfLocal/DeadStoreOfLocal.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
| DeadStoreOfLocal.cs:320:9:320:32 | ... = ... | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocal.cs:316:23:316:23 | b | b |
1717
| DeadStoreOfLocal.cs:361:13:361:20 | String s = ... | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocal.cs:361:13:361:13 | s | s |
1818
| DeadStoreOfLocal.cs:387:13:387:21 | ... = ... | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocal.cs:385:13:385:13 | s | s |
19-
| DeadStoreOfLocal.cs:434:22:434:22 | T _ | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocal.cs:434:22:434:22 | _ | _ |
2019
| DeadStoreOfLocalBad.cs:7:13:7:48 | Boolean success = ... | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocalBad.cs:7:13:7:19 | success | success |
2120
| DeadStoreOfLocalBad.cs:23:32:23:32 | FormatException e | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocalBad.cs:23:32:23:32 | e | e |
2221
| DeadStoreOfLocalBad.cs:32:22:32:22 | String s | This assignment to $@ is useless, since its value is never read. | DeadStoreOfLocalBad.cs:32:22:32:22 | s | s |

0 commit comments

Comments
 (0)