We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 432ac7a commit ba67ea0Copy full SHA for ba67ea0
1 file changed
csharp/ql/src/Language Abuse/UselessNullCoalescingExpression.ql
@@ -14,11 +14,19 @@
14
import csharp
15
import semmle.code.csharp.commons.StructuralComparison
16
17
+pragma[noinline]
18
+private predicate same(AssignableAccess x, AssignableAccess y) {
19
+ exists(NullCoalescingExpr nce |
20
+ x = nce.getLeftOperand() and
21
+ y = nce.getRightOperand().getAChildExpr*()
22
+ ) and
23
+ sameGvn(x, y)
24
+}
25
+
26
private predicate uselessNullCoalescingExpr(NullCoalescingExpr nce) {
- forex(AssignableAccess y |
- y = nce.getRightOperand().getAChildExpr*() and sameGvn(nce.getLeftOperand(), y)
- |
- y instanceof AssignableRead and not y.isRefArgument()
27
+ exists(AssignableAccess x |
28
+ nce.getLeftOperand() = x and
29
+ forex(AssignableAccess y | same(x, y) | y instanceof AssignableRead and not y.isRefArgument())
30
)
31
}
32
0 commit comments