Skip to content

Commit e9d74ed

Browse files
committed
Add test to verify we diagnose incorrect lifetime annotation
1 parent f861007 commit e9d74ed

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

test/SILOptimizer/lifetime_dependence_borrow_fail.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
// RUN: -verify \
44
// RUN: -sil-verify-all \
55
// RUN: -module-name test \
6-
// RUN: -enable-experimental-feature NoncopyableGenerics \
7-
// RUN: -enable-experimental-feature NonescapableTypes
6+
// RUN: -enable-experimental-feature NonescapableTypes \
7+
// RUN: -enable-experimental-feature NoncopyableGenerics
88

99
// REQUIRES: asserts
1010
// REQUIRES: swift_in_compiler
@@ -54,3 +54,15 @@ func bv_get_consume(container: consuming NE) -> BV {
5454
// expected-note @-2{{this use causes the lifetime-dependent value to escape}}
5555
}
5656

57+
struct Wrapper : ~Escapable {
58+
let bv: BV
59+
}
60+
61+
func bv_incorrect_annotation1(_ bv1: borrowing BV, _ bv2: borrowing BV) -> dependsOn(bv2) BV { // expected-error {{lifetime-dependent variable 'bv1' escapes its scope}}
62+
return copy bv1 // expected-note @-1{{it depends on the lifetime of argument 'bv1'}}
63+
} // expected-note @-1{{this use causes the lifetime-dependent value to escape}}
64+
65+
func bv_incorrect_annotation2(_ w1: borrowing Wrapper, _ w2: borrowing Wrapper) -> dependsOn(w2) BV { // expected-error {{lifetime-dependent variable 'w1' escapes its scope}}
66+
return w1.bv // expected-note @-1{{it depends on the lifetime of argument 'w1'}}
67+
} // expected-note @-1{{this use causes the lifetime-dependent value to escape}}
68+

0 commit comments

Comments
 (0)