Python: move restriction into branch predicate

Otherwise we get loads of nodes with missing locations
from the brnach nodes that are not matched.
This commit is contained in:
Rasmus Lerchedahl Petersen
2023-12-16 00:33:11 +01:00
parent 5de1725648
commit 661ba1ca7b
2 changed files with 5 additions and 8 deletions

View File

@@ -1534,11 +1534,7 @@ class SynthCapturingClosureParameterNode extends ParameterNodeImpl,
{
private Function callable;
SynthCapturingClosureParameterNode() {
this = TSynthCapturingClosureParameterNode(callable) and
// TODO: Remove this restriction when adding proper support for captured variables in the body of the function we generate for comprehensions
exists(TFunction(callable))
}
SynthCapturingClosureParameterNode() { this = TSynthCapturingClosureParameterNode(callable) }
final Function getCallable() { result = callable }
@@ -1661,7 +1657,7 @@ class CapturingClosureArgumentNode extends CfgNode, ArgumentNode {
CallNode callNode;
CapturingClosureArgumentNode() {
this.getNode() = callNode.getFunction() and
node = callNode.getFunction() and
exists(Function target | resolveCall(callNode, target, _) |
target = any(VariableCapture::CapturedVariable v).getACapturingScope()
)
@@ -1669,7 +1665,6 @@ class CapturingClosureArgumentNode extends CfgNode, ArgumentNode {
override string toString() { result = "Capturing closure argument" }
// final override Location getLocation() { result = callNode.getLocation() }
override predicate argumentOf(DataFlowCall call, ArgumentPosition pos) {
callNode = call.getNode() and
pos.isLambdaSelf()

View File

@@ -119,7 +119,9 @@ newtype TNode =
TSynthCaptureNode(VariableCapture::Flow::SynthesizedCaptureNode cn) or
/** A synthetic node representing the heap of a function. Used for variable capture. */
TSynthCapturingClosureParameterNode(Function f) {
f = any(VariableCapture::CapturedVariable v).getACapturingScope()
f = any(VariableCapture::CapturedVariable v).getACapturingScope() and
// TODO: Remove this restriction when adding proper support for captured variables in the body of the function we generate for comprehensions
exists(TFunction(f))
}
private import semmle.python.internal.CachedStages