Skip to content

Commit b832fc8

Browse files
committed
Swift: additional QLDoc around closures
1 parent dd71204 commit b832fc8

File tree

4 files changed

+17
-2
lines changed

4 files changed

+17
-2
lines changed

swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowElements.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ predicate isPropertyGetterElement(PropertyGetterElement pge, Accessor accessor,
4242
}
4343

4444
predicate isNormalAutoClosureOrExplicitClosure(ClosureExpr clos) {
45+
// short-circuiting operators have a `BinaryExpr` as the parent of the `AutoClosureExpr`,
46+
// so we exclude them by checking for a `CallExpr`.
4547
clos instanceof AutoClosureExpr and
4648
exists(CallExpr call | call.getAnArgument().getExpr() = clos)
4749
or
@@ -201,6 +203,10 @@ class KeyPathElement extends ControlFlowElement, TKeyPathElement {
201203
override string toString() { result = expr.toString() }
202204
}
203205

206+
/**
207+
* A control flow element representing a closure in its role as a control flow
208+
* scope.
209+
*/
204210
class ClosureElement extends ControlFlowElement, TClosureElement {
205211
ClosureExpr expr;
206212

swift/ql/lib/codeql/swift/controlflow/internal/ControlFlowGraphImpl.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1148,6 +1148,10 @@ module Exprs {
11481148
}
11491149
}
11501150

1151+
/**
1152+
* The control flow for an explicit closure or a normal autoclosure in its
1153+
* role as a control flow scope.
1154+
*/
11511155
class ClosureExprTree extends StandardPreOrderTree, TClosureElement {
11521156
ClosureExpr expr;
11531157

swift/ql/lib/codeql/swift/elements/expr/AutoClosureExpr.qll

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ private import codeql.swift.elements.expr.Expr
44

55
/**
66
* A Swift autoclosure expression, that is, a closure automatically generated
7-
* around an argument when the parameter has the `@autoclosure` attribute. For
7+
* around an argument when the parameter has the `@autoclosure` attribute or
8+
* for the rtight-hand operand of short-circuiting logical operations. For
89
* example, there is an `AutoClosureExpr` around the value `0` in:
910
* ```
1011
* func myFunction(_ expr: @autoclosure () -> Int) {

swift/ql/lib/codeql/swift/elements/expr/ExplicitClosureExpr.qll

Lines changed: 5 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)