@@ -74,7 +74,17 @@ extension Array {
74
74
}
75
75
}
76
76
77
- struct Inner {
77
+ struct InnerTrivial {
78
+ var p : UnsafePointer < Int >
79
+
80
+ @lifetime ( borrow self)
81
+ borrowing func span( ) -> Span < Int > {
82
+ Span ( base: p, count: 1 )
83
+ }
84
+ }
85
+
86
+ struct InnerObject {
87
+ let object : AnyObject
78
88
var p : UnsafePointer < Int >
79
89
80
90
@lifetime ( borrow self)
@@ -84,14 +94,31 @@ struct Inner {
84
94
}
85
95
86
96
struct Outer {
87
- let inner : Inner
88
- let fakePointer : UnsafePointer < Inner >
97
+ var _innerTrivial : InnerTrivial
98
+ var _innerObject : InnerObject
99
+ let trivialPointer : UnsafePointer < InnerTrivial >
100
+ let objectPointer : UnsafePointer < InnerObject >
89
101
90
- var innerAddress : Inner {
102
+ var innerTrivialAddress : InnerTrivial {
91
103
unsafeAddress {
92
- fakePointer
104
+ trivialPointer
93
105
}
94
106
}
107
+
108
+ var innerObjectAddress : InnerObject {
109
+ unsafeAddress {
110
+ objectPointer
111
+ }
112
+ }
113
+
114
+ var innerTrivialTemp : InnerTrivial {
115
+ get { _innerTrivial }
116
+ }
117
+
118
+ var innerObjectTemp : InnerObject {
119
+ get { _innerObject }
120
+ }
121
+
95
122
/* TODO: rdar://137608270 Add Builtin.addressof() support for @addressable arguments
96
123
@addressableSelf
97
124
var innerAddress: Inner {
@@ -206,11 +233,63 @@ func testTrivialScope<T>(a: Array<T>) -> Span<T> {
206
233
// =============================================================================
207
234
208
235
@lifetime ( borrow outer)
209
- func testBorrowComponent( outer: Outer ) -> Span < Int > {
210
- outer. inner. span ( )
236
+ func testBorrowStoredTrivial( outer: Outer ) -> Span < Int > {
237
+ outer. _innerTrivial. span ( )
238
+ }
239
+
240
+ @lifetime ( borrow outer)
241
+ func testBorrowStoredObject( outer: Outer ) -> Span < Int > {
242
+ outer. _innerObject. span ( )
211
243
}
212
244
213
245
@lifetime ( borrow outer)
214
- func testBorrowAddressComponent ( outer: Outer ) -> Span < Int > {
215
- outer. innerAddress . span ( )
246
+ func testBorrowTrivialAddressProjection ( outer: Outer ) -> Span < Int > {
247
+ outer. innerTrivialAddress . span ( )
216
248
}
249
+
250
+ @lifetime ( borrow outer)
251
+ func testBorrowObjectAddressProjection( outer: Outer ) -> Span < Int > {
252
+ outer. innerObjectAddress. span ( )
253
+ }
254
+
255
+ func testExprExtendTrivialTemp( outer: Outer ) {
256
+ parse ( outer. innerTrivialTemp. span ( ) )
257
+ // expected-error @-1{{lifetime-dependent value escapes its scope}}
258
+ // expected-note @-2{{it depends on the lifetime of this parent value}}
259
+ // expected-note @-3{{this use of the lifetime-dependent value is out of scope}}
260
+ }
261
+
262
+ func testExprExtendObjectTemp( outer: Outer ) {
263
+ parse ( outer. innerObjectTemp. span ( ) )
264
+ // expected-error @-1{{lifetime-dependent value escapes its scope}}
265
+ // expected-note @-2{{it depends on the lifetime of this parent value}}
266
+ // expected-note @-3{{this use of the lifetime-dependent value is out of scope}}
267
+ }
268
+
269
+ func testLocalExtendTrivialTemp( outer: Outer ) {
270
+ let span = outer. innerTrivialTemp. span ( )
271
+ // expected-error @-1{{lifetime-dependent variable 'span' escapes its scope}}
272
+ // expected-note @-2{{it depends on the lifetime of this parent value}}
273
+ parse ( span) // expected-note {{this use of the lifetime-dependent value is out of scope}}
274
+ }
275
+
276
+ func testLocalExtendObjectTemp( outer: Outer ) {
277
+ let span = outer. innerObjectTemp. span ( )
278
+ // expected-error @-1{{lifetime-dependent variable 'span' escapes its scope}}
279
+ // expected-note @-2{{it depends on the lifetime of this parent value}}
280
+ parse ( span) // expected-note {{this use of the lifetime-dependent value is out of scope}}
281
+ }
282
+
283
+ @lifetime ( borrow outer)
284
+ func testReturnTrivialTemp( outer: Outer ) -> Span < Int > {
285
+ outer. innerTrivialTemp. span ( )
286
+ // expected-error @-1{{lifetime-dependent value escapes its scope}}
287
+ // expected-note @-2{{it depends on the lifetime of this parent value}}
288
+ } // expected-note {{this use causes the lifetime-dependent value to escape}}
289
+
290
+ @lifetime ( borrow outer)
291
+ func testReturnObjectTemp( outer: Outer ) -> Span < Int > {
292
+ outer. innerObjectTemp. span ( )
293
+ // expected-error @-1{{lifetime-dependent value escapes its scope}}
294
+ // expected-note @-2{{it depends on the lifetime of this parent value}}
295
+ } // expected-note {{this use causes the lifetime-dependent value to escape}}
0 commit comments