Skip to content

Commit 784bb72

Browse files
committed
Swift: Add some more tests.
1 parent 96a37f3 commit 784bb72

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

swift/ql/test/library-tests/dataflow/capture/closures.swift

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,40 @@ func sideEffects() {
137137
f()
138138
sink(x) // $ hasValueFlow=sideEffects
139139
}
140+
141+
class S {
142+
var bf1 = 0
143+
var bf2 = 0
144+
func captureOther() {
145+
var other = S()
146+
var f = { x in
147+
other.bf1 = x;
148+
};
149+
150+
// no flow
151+
sink(bf1);
152+
sink(other.bf1);
153+
sink(other.bf2);
154+
155+
f(source("captureOther", 2));
156+
157+
sink(other.bf1); // $ hasValueFlow=captureOther
158+
sink(other.bf2);
159+
}
160+
161+
func captureThis() {
162+
var f = { [self] x in
163+
self.bf1 = x;
164+
bf2 = x;
165+
};
166+
167+
// no flow
168+
sink(bf1);
169+
sink(self.bf2);
170+
171+
f(source("captureThis", 2));
172+
173+
sink(bf1); // $ MISSING: hasValueFlow
174+
sink(self.bf2); // $ MISSING: hasValueFlow
175+
}
176+
}

0 commit comments

Comments
 (0)