Skip to content

Commit 621674e

Browse files
committed
C#: Update cs/static/field-written-by-instance to handle properties.
1 parent 687f3c6 commit 621674e

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/**
22
* @name Static field written by instance method
3-
* @description Finds instance methods that write static fields.
3+
* @description Finds instance methods and properties that write to static fields.
44
* This is tricky to get right if multiple instances are being manipulated,
55
* and generally bad practice.
66
* @kind problem
@@ -14,12 +14,12 @@
1414

1515
import csharp
1616

17-
from FieldWrite fw, Field f, Callable m
17+
from FieldWrite fw, Field f, Callable c
1818
where
1919
fw.getTarget() = f and
2020
f.isStatic() and
21-
m = fw.getEnclosingCallable() and
22-
not m.(Member).isStatic() and
23-
f.getDeclaringType() = m.getDeclaringType() and
24-
m.fromSource()
25-
select fw.(VariableAccess), "Write to static field from instance method or constructor."
21+
c = fw.getEnclosingCallable() and
22+
not exists(Member m | m = c or m = c.(Accessor).getDeclaration() | m.isStatic()) and
23+
f.getDeclaringType() = c.getDeclaringType() and
24+
c.fromSource()
25+
select fw.(VariableAccess), "Write to static field from instance method, property or constructor."

0 commit comments

Comments
 (0)