File tree Expand file tree Collapse file tree 1 file changed +34
-0
lines changed
test/SILOptimizer/lifetime_dependence Expand file tree Collapse file tree 1 file changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,17 @@ struct Holder {
4949 var c : C ? = nil
5050}
5151
52+ // Generic non-Escapable for indirect values.
53+ struct GNE < T> : ~ Escapable {
54+ let t : T
55+ @lifetime ( borrow t)
56+ init ( t: borrowing T ) { self . t = copy t }
57+ }
58+
59+ @_silgen_name ( " forward " )
60+ @lifetime ( copy arg)
61+ func forward< T> ( _ arg: GNE < T > ) -> GNE < T >
62+
5263@_silgen_name ( " getGeneric " )
5364@lifetime ( borrow holder)
5465func getGeneric< T : ~ Escapable> ( _ holder: borrowing Holder , _: T . Type ) -> T
@@ -156,3 +167,26 @@ func testClosureCapture1(_ a: HasMethods) {
156167 }
157168 */
158169}
170+
171+ // =============================================================================
172+ // Indirect ~Escapable results
173+ // =============================================================================
174+
175+ @lifetime ( copy arg1)
176+ func testIndirectForwardedResult< T> ( arg1: GNE < T > ) -> GNE < T > {
177+ forward ( arg1)
178+ }
179+
180+ @lifetime ( copy arg1)
181+ func testIndirectNonForwardedResult< T> ( arg1: GNE < T > , arg2: GNE < T > ) -> GNE < T > {
182+ // expected-error @-1{{lifetime-dependent variable 'arg2' escapes its scope}}
183+ // expected-note @-2{{it depends on the lifetime of argument 'arg2'}}
184+ forward ( arg2) // expected-note {{this use causes the lifetime-dependent value to escape}}
185+ }
186+
187+ func testIndirectClosureResult< T> ( f: ( ) -> GNE < T > ) -> GNE < T > {
188+ f ( )
189+ // expected-error @-1{{lifetime-dependent variable '$return_value' escapes its scope}}
190+ // expected-note @-3{{it depends on the lifetime of argument '$return_value'}}
191+ // expected-note @-3{{this use causes the lifetime-dependent value to escape}}
192+ }
You can’t perform that action at this time.
0 commit comments