Skip to content

Commit c395d2d

Browse files
yoffRasmusWL
andauthored
Apply suggestions from code review
Co-authored-by: Rasmus Wriedt Larsen <[email protected]>
1 parent abd544d commit c395d2d

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,11 @@ abstract class ParameterNodeImpl extends Node {
15311531
class LambdaSelfReferenceNode extends ParameterNodeImpl, TLambdaSelfReferenceNode {
15321532
private Function callable;
15331533

1534-
LambdaSelfReferenceNode() { this = TLambdaSelfReferenceNode(callable) }
1534+
LambdaSelfReferenceNode() {
1535+
this = TLambdaSelfReferenceNode(callable) and
1536+
// TODO: Remove this restriction when adding proper support for captured variables in the body of the function we generate for comprehensions
1537+
exists(TFunction(callable))
1538+
}
15351539

15361540
final Function getCallable() { result = callable }
15371541

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPrivate.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ module VariableCapture {
392392
ExprCfgNode() { isExpressionNode(this) }
393393
}
394394

395-
private predicate closureFlowStep(ExprCfgNode e1, ExprCfgNode e2) {
395+
private predicate closureFlowStep(ExprCfgNode fromNode, ExprCfgNode toNode) {
396396
// simpleAstFlowStep(e1, e2)
397397
// or
398398
exists(SsaVariable def |
@@ -689,7 +689,7 @@ predicate summaryFlowSteps(Node nodeFrom, Node nodeTo) {
689689
IncludePostUpdateFlow<PhaseDependentFlow<summaryLocalStep/2>::step/2>::step(nodeFrom, nodeTo)
690690
}
691691

692-
predicate variableCaptureFlowStep(Node nodeFrom, Node nodeTo) {
692+
predicate variableCaptureLocalFlowStep(Node nodeFrom, Node nodeTo) {
693693
// Blindly applying use-use flow can result in a node that steps to itself, for
694694
// example in while-loops. To uphold dataflow consistency checks, we don't want
695695
// that. However, we do want to allow `[post] n` to `n` (to handle while loops), so

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPublic.qll

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ newtype TNode =
116116
exists(ParameterPosition ppos | ppos.isKeyword(_) | exists(callable.getParameter(ppos)))
117117
} or
118118
/** A synthetic node representing a captured variable. */
119-
TCaptureNode(VariableCapture::Flow::SynthesizedCaptureNode cn) or
119+
TSynthCaptureNode(VariableCapture::Flow::SynthesizedCaptureNode cn) or
120120
/** A synthetic node representing the heap of a function. Used for variable capture. */
121121
TLambdaSelfReferenceNode(Function f) {
122122
f = any(VariableCapture::CapturedVariable v).getACapturingScope()
@@ -489,10 +489,8 @@ class CaptureNode extends Node, TCaptureNode {
489489
/** Gets the `SynthesizedCaptureNode` that this node represents. */
490490
VariableCapture::Flow::SynthesizedCaptureNode getSynthesizedCaptureNode() { result = cn }
491491

492-
override DataFlowCallable getEnclosingCallable() {
493-
result = TFunction(cn.getEnclosingCallable())
494-
or
495-
result = TModule(cn.getEnclosingCallable())
492+
override Scope getScope() {
493+
result = cn.getEnclosingCallable()
496494
}
497495

498496
override Location getLocation() { result = cn.getLocation() }

0 commit comments

Comments
 (0)