Skip to content

Commit 3577b27

Browse files
committed
Fix to not report on enum member initialization
1 parent 77bb1b2 commit 3577b27

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

csharp/ql/src/Likely Bugs/SelfAssignment.ql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ class StructuralComparisonConfig extends StructuralComparisonConfiguration {
2020
exists(AssignExpr ae |
2121
// Member initializers are never self-assignments, in particular
2222
// not initializers such as `new C { F = F };`
23-
not ae instanceof MemberInitializer
23+
not ae instanceof MemberInitializer and
24+
// Enum field initializers are never self assignments. `enum E { A = 42 }`
25+
not ae.getParent().(Field).getDeclaringType() instanceof Enum
2426
|
2527
ae.getLValue() = x and
2628
ae.getRValue() = y

csharp/ql/test/query-tests/Likely Bugs/SelfAssignment/selfassigns.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,4 +82,11 @@ public void NotOK(SelfAssigns obj, int y)
8282
this.Self.Self.Self.StringProp = Self.Self.Self.StringProp;
8383
intArray[1] = this.intArray[1 + 0];
8484
}
85+
86+
enum Enum
87+
{
88+
X = 42,
89+
Y = 100,
90+
Z
91+
}
8592
}

0 commit comments

Comments
 (0)