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 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
1414
1515import csharp
1616
17- from FieldWrite fw , Field f , Callable m
17+ from FieldWrite fw , Field f , Callable c
1818where
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."
You can’t perform that action at this time.
0 commit comments