We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8528021 commit 3a95db9Copy full SHA for 3a95db9
test/expr/implicit_weak_capture.swift
@@ -0,0 +1,29 @@
1
+// RUN: %target-run-simple-swift(-Xfrontend -disable-availability-checking)
2
+
3
+// REQUIRES: executable_test
4
5
+func runIn10ms(_ closure: @escaping @Sendable () -> Void) {
6
+ Task {
7
+ try! await Task.sleep(nanoseconds: 10_000_000)
8
+ closure()
9
+ }
10
+}
11
12
+final class Weak: Sendable {
13
+ let property = "Self exists"
14
15
+ func test() {
16
+ runIn10ms { [weak self] in
17
+ if let self {
18
+ // Use implicit self -- this should not result in a strong capture
19
+ _ = property
20
+ fatalError("Self was unexpectedly captured strongly")
21
+ } else {
22
+ print("Self was captured weakly")
23
24
25
26
27
28
+Weak().test()
29
+try await Task.sleep(nanoseconds: 20_000_000)
0 commit comments