-
Notifications
You must be signed in to change notification settings - Fork 10.5k
/
Copy pathlexical-lifetimes.swift
56 lines (45 loc) · 1.91 KB
/
lexical-lifetimes.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// RUN: %target-run-simple-swift(-Xfrontend -enable-experimental-lexical-lifetimes -Xfrontend -enable-copy-propagation) | %FileCheck %s
// REQUIRES: executable_test
// =============================================================================
// = Declarations {{ =
// =============================================================================
class C {
init(_ d: D) {
self.d = d
}
weak var d: D?
func foo(_ string: String) {
d?.cWillFoo(self, string)
}
}
class D {
func cWillFoo(_ c: C, _ string: String) {
print(#function, string)
}
}
// =============================================================================
// = Declarations }} =
// =============================================================================
// =============================================================================
// = Tests {{ =
// =============================================================================
func test_localLetKeepsObjectAliveBeyondCallToClassWithWeakReference() {
let d = D()
let c = C(d)
// CHECK: cWillFoo{{.*}} test_localLetKeepsObjectAliveBeyondCallToClassWithWeakReference
c.foo(#function)
}
func test_localVarKeepsObjectAliveBeyondCallToClassWithWeakReference() {
var d = D()
let c = C(d)
// CHECK: cWillFoo{{.*}} test_localVarKeepsObjectAliveBeyondCallToClassWithWeakReference
c.foo(#function)
}
// =============================================================================
// = Tests }} =
// =============================================================================
func run() {
test_localLetKeepsObjectAliveBeyondCallToClassWithWeakReference()
test_localVarKeepsObjectAliveBeyondCallToClassWithWeakReference()
}
run()