C#: Update cs/static/field-written-by-instance to handle properties.

This commit is contained in:
Michael Nebel
2023-02-28 12:13:48 +01:00
parent 687f3c6b2e
commit 621674e82e

View File

@@ -1,6 +1,6 @@
/**
* @name Static field written by instance method
* @description Finds instance methods that write static fields.
* @description Finds instance methods and properties that write to static fields.
* This is tricky to get right if multiple instances are being manipulated,
* and generally bad practice.
* @kind problem
@@ -14,12 +14,12 @@
import csharp
from FieldWrite fw, Field f, Callable m
from FieldWrite fw, Field f, Callable c
where
fw.getTarget() = f and
f.isStatic() and
m = fw.getEnclosingCallable() and
not m.(Member).isStatic() and
f.getDeclaringType() = m.getDeclaringType() and
m.fromSource()
select fw.(VariableAccess), "Write to static field from instance method or constructor."
c = fw.getEnclosingCallable() and
not exists(Member m | m = c or m = c.(Accessor).getDeclaration() | m.isStatic()) and
f.getDeclaringType() = c.getDeclaringType() and
c.fromSource()
select fw.(VariableAccess), "Write to static field from instance method, property or constructor."