Skip to content

Commit ce2e7f1

Browse files
committed
Swift: all Callables can have captures [hand-written]
1 parent d230431 commit ce2e7f1

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

swift/extractor/translators/DeclTranslator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,7 @@ void DeclTranslator::fillAbstractFunctionDecl(const swift::AbstractFunctionDecl&
334334
entry.params = dispatcher.fetchRepeatedLabels(*decl.getParameters());
335335
auto self = const_cast<swift::ParamDecl* const>(decl.getImplicitSelfDecl());
336336
entry.self_param = dispatcher.fetchOptionalLabel(self);
337+
entry.captures = dispatcher.fetchRepeatedLabels(decl.getCaptureInfo().getCaptures());
337338
fillValueDecl(decl, entry);
338339
fillGenericContext(decl, entry);
339340
}

swift/ql/test/extractor-tests/generated/decl/CapturedDecl/closures.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,19 @@ func foo() {
88
print(x)
99
print(y) }()
1010
}
11+
12+
var escape: (() -> ())? = nil
13+
14+
func baz() {
15+
var x = 0
16+
func quux() {
17+
x += 1
18+
print(x)
19+
}
20+
escape = quux
21+
}
22+
23+
func callEscape() {
24+
baz()
25+
escape?()
26+
}

swift/schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ class Callable(Element):
229229
self_param: optional[ParamDecl] | child
230230
params: list[ParamDecl] | child
231231
body: optional["BraceStmt"] | child | desc("The body is absent within protocol declarations.")
232+
captures: list["CapturedDecl"] | child
232233

233234
class AbstractFunctionDecl(GenericContext, ValueDecl, Callable):
234235
pass
@@ -340,7 +341,7 @@ class Argument(Locatable):
340341
expr: Expr | child
341342

342343
class AbstractClosureExpr(Expr, Callable):
343-
captures: list["CapturedDecl"] | child
344+
pass
344345

345346
class AnyTryExpr(Expr):
346347
sub_expr: Expr | child

0 commit comments

Comments
 (0)