File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed
csharp/ql/src/Likely Bugs Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 1
1
/**
2
2
* @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.
4
4
* This is tricky to get right if multiple instances are being manipulated,
5
5
* and generally bad practice.
6
6
* @kind problem
14
14
15
15
import csharp
16
16
17
- from FieldWrite fw , Field f , Callable m
17
+ from FieldWrite fw , Field f , Callable c
18
18
where
19
19
fw .getTarget ( ) = f and
20
20
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."
You can’t perform that action at this time.
0 commit comments