Skip to content

Commit 0a4dd8c

Browse files
committed
Add unit test for lifetime dependence related to function types
1 parent 83fbc6b commit 0a4dd8c

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature NonescapableTypes
2+
// REQUIRES: asserts
3+
4+
struct NC: ~Copyable {
5+
var ne: NE {
6+
NE()
7+
}
8+
}
9+
10+
struct NE: ~Escapable {
11+
@_unsafeNonescapableResult
12+
init() {}
13+
}
14+
15+
func transfer(_ ne: NE) -> NE {
16+
ne
17+
}
18+
19+
func applyAnnotatedTransfer(ne: NE, transfer: (NE) -> dependsOn(0) NE) -> NE { // expected-error{{Lifetime dependencies on function types are not yet supported}}
20+
transfer(ne)
21+
}
22+
23+
func applyTransfer(ne: NE, transfer: (NE) -> NE) -> NE {
24+
transfer(ne)
25+
}
26+
27+
func testTransfer(nc: consuming NC) {
28+
let transferred = applyTransfer(ne: nc.ne, transfer: transfer) // expected-error{{Conversion between function types with different lifetime dependencies are not allowed}}
29+
30+
_ = consume nc
31+
_ = transfer(transferred)
32+
}
33+
34+
func borrow(_ nc: borrowing NC) -> NE {
35+
nc.ne
36+
}
37+
38+
func applyBorrow(nc: borrowing NC, borrow: (borrowing NC) -> NE) -> NE {
39+
borrow(nc)
40+
}
41+
42+
func testBorrow(nc: consuming NC) {
43+
let borrowed = applyBorrow(nc: nc, borrow: borrow) // expected-error{{Conversion between function types with different lifetime dependencies are not allowed}}
44+
_ = consume nc
45+
_ = transfer(borrowed)
46+
}
47+

0 commit comments

Comments
 (0)