-
Notifications
You must be signed in to change notification settings - Fork 1.8k
C#: Update query to handle static field writes from properties. #12334
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
C#: Update query to handle static field writes from properties. #12334
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One question and one suggestion, otherwise looks good.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Question: could this be implemented like this:
not exists(Member m | m = c or m = c.(Accessor).getDeclaration() | m.isStatic()) and | |
not (c.(Member).isStatic() or c.(Accessor).getDeclaration().isStatic()) and |
and would that (potentially) be better for performance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or even shorter
not [c.(Member), c.(Accessor).getDeclaration()].isStatic()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it can be implemented like this, but I don't think that it will have any effect on performance.
I prefer the original solution as it re-uses the isStatic
logic across the relevant members.
I prefer Toms suggestion.
6e7778b
to
8bf81ab
Compare
8bf81ab
to
5174662
Compare
It turns out that the query
cs/static-field-written-by-instance
reports false positives if a static property writes to static field.That is, the example below leads to a false positive. This is fixed in this PR.