Skip to content

Commit 01ce96c

Browse files
gregomnijckarter
authored andcommitted
Add tests for capturing dynamicSelf
1 parent 7f6d600 commit 01ce96c

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

test/SILGen/capture-transitive.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,24 @@ func fibonacci(_ n: Int) -> Int {
1818
return recursive(n)
1919
}
2020

21+
class C {
22+
required init() {}
23+
func f() {}
24+
// Make sure that we capture dynamic self type if an explicit self isn't guaranteed
25+
func returnsSelf() -> Self {
26+
return { self.f(); return .init() }()
27+
// CHECK-LABEL: sil private @{{.*}}returnsSelf{{.*}} : $@convention(thin) (@guaranteed C) -> @owned C
28+
}
29+
30+
func returnsSelf1() -> Self {
31+
return { [weak self] in self?.f(); return .init() }()
32+
// CHECK-LABEL: sil private @{{.*}}returnsSelf{{.*}} : $@convention(thin) (@guaranteed { var @sil_weak Optional<C> }, @thick @dynamic_self C.Type) -> @owned C
33+
}
34+
35+
func returnsSelf2() -> Self {
36+
return { [unowned self] in self.f(); return .init() }()
37+
// CHECK-LABEL: sil private @{{.*}}returnsSelf{{.*}} : $@convention(thin) (@guaranteed @sil_unowned C, @thick @dynamic_self C.Type) -> @owned C
38+
}
39+
}
40+
41+

0 commit comments

Comments
 (0)