Skip to content

Commit 1d1780b

Browse files
committed
C#: Fix bug in getEnclosingCallable
1 parent f85fa87 commit 1d1780b

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

csharp/ql/lib/semmle/code/csharp/ExprOrStmtParent.qll

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,9 @@ private module Cached {
140140
}
141141

142142
private Expr getAChildExpr(ExprOrStmtParent parent) {
143-
result = parent.getAChildExpr() or
143+
result = parent.getAChildExpr() and
144+
not result = parent.(DeclarationWithGetSetAccessors).getExpressionBody()
145+
or
144146
result = parent.(AssignOperation).getExpandedAssignment()
145147
}
146148

@@ -159,7 +161,7 @@ private module Cached {
159161

160162
private predicate parent(ControlFlowElement child, ExprOrStmtParent parent) {
161163
child = getAChild(parent) and
162-
not child instanceof Callable
164+
not child = any(Callable c).getBody()
163165
}
164166

165167
/** Holds if the enclosing body of `cfe` is `body`. */

csharp/ql/test/library-tests/controlflow/graph/EnclosingCallable.expected

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4882,17 +4882,11 @@ nodeEnclosing
48824882
| cflow.cs:306:60:310:5 | exit get__getter | cflow.cs:306:60:310:5 | get__getter |
48834883
| cflow.cs:306:60:310:5 | exit get__getter (normal) | cflow.cs:306:60:310:5 | get__getter |
48844884
| cflow.cs:307:5:310:5 | {...} | cflow.cs:306:60:310:5 | (...) => ... |
4885-
| cflow.cs:307:5:310:5 | {...} | cflow.cs:306:60:310:5 | get__getter |
48864885
| cflow.cs:308:9:308:21 | ... ...; | cflow.cs:306:60:310:5 | (...) => ... |
4887-
| cflow.cs:308:9:308:21 | ... ...; | cflow.cs:306:60:310:5 | get__getter |
48884886
| cflow.cs:308:16:308:20 | Object x = ... | cflow.cs:306:60:310:5 | (...) => ... |
4889-
| cflow.cs:308:16:308:20 | Object x = ... | cflow.cs:306:60:310:5 | get__getter |
48904887
| cflow.cs:308:20:308:20 | access to parameter o | cflow.cs:306:60:310:5 | (...) => ... |
4891-
| cflow.cs:308:20:308:20 | access to parameter o | cflow.cs:306:60:310:5 | get__getter |
48924888
| cflow.cs:309:9:309:17 | return ...; | cflow.cs:306:60:310:5 | (...) => ... |
4893-
| cflow.cs:309:9:309:17 | return ...; | cflow.cs:306:60:310:5 | get__getter |
48944889
| cflow.cs:309:16:309:16 | access to local variable x | cflow.cs:306:60:310:5 | (...) => ... |
4895-
| cflow.cs:309:16:309:16 | access to local variable x | cflow.cs:306:60:310:5 | get__getter |
48964890
blockEnclosing
48974891
| AccessorCalls.cs:5:23:5:25 | enter get_Item | AccessorCalls.cs:5:23:5:25 | get_Item |
48984892
| AccessorCalls.cs:5:33:5:35 | enter set_Item | AccessorCalls.cs:5:33:5:35 | set_Item |

0 commit comments

Comments
 (0)