Skip to content

Commit 1f2cda9

Browse files
committed
C#: Implement isVariableCaptureContentSet
1 parent 5c9e79e commit 1f2cda9

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPrivate.qll

+5-8
Original file line numberDiff line numberDiff line change
@@ -1158,7 +1158,8 @@ private module Cached {
11581158
cached
11591159
newtype TContentSet =
11601160
TSingletonContent(Content c) { not c instanceof PropertyContent } or
1161-
TPropertyContentSet(Property p) { p.isUnboundDeclaration() }
1161+
TPropertyContentSet(Property p) { p.isUnboundDeclaration() } or
1162+
TVariableCaptureContentSet()
11621163

11631164
cached
11641165
newtype TContentApprox =
@@ -2952,13 +2953,9 @@ Content getLambdaArgumentContent(LambdaCallKind kind, ArgumentPosition pos) {
29522953
exists(kind)
29532954
}
29542955

2955-
predicate isLambdaInstanceParameter(ParameterNode p) {
2956-
exists(DataFlowCallable c, ParameterPosition ppos |
2957-
lambdaCreation(_, _, c) and
2958-
isParameterNode(p, c, ppos) and
2959-
ppos.isDelegateSelf()
2960-
)
2961-
}
2956+
predicate isLambdaInstanceParameter(ParameterNode p) { p instanceof DelegateSelfReferenceNode }
2957+
2958+
predicate isVariableCaptureContentSet(ContentSet c) { c.isCapturedVariable() }
29622959

29632960
private predicate isLocalFunctionCallReceiver(
29642961
LocalFunctionCall call, LocalFunctionAccess receiver, LocalFunction f

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowPublic.qll

+5
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,8 @@ class ContentSet extends TContentSet {
323323
*/
324324
predicate isProperty(Property p) { this = TPropertyContentSet(p) }
325325

326+
predicate isCapturedVariable() { this = TVariableCaptureContentSet() }
327+
326328
/**
327329
* Holds if this content set represents the `i`th argument of a delegate call.
328330
*/
@@ -361,6 +363,9 @@ class ContentSet extends TContentSet {
361363
or
362364
overridesOrImplementsSourceDecl(p1, p2)
363365
)
366+
or
367+
this.isCapturedVariable() and
368+
result instanceof CapturedVariableContent
364369
}
365370

366371
/** Gets a textual representation of this content set. */

0 commit comments

Comments
 (0)