Skip to content

Commit 1707ddb

Browse files
committed
Add a lifetime test for empty initialization.
Test for rdar://131176898 ([nonescapable] missing diagnostic for incorrectly inferred inherited dependence)
1 parent f5637fc commit 1707ddb

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

test/SILOptimizer/lifetime_dependence/semantics.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ internal func _overrideLifetime<
5858
dependent
5959
}
6060

61+
struct NotEscapable: ~Escapable {}
62+
6163
// Lifetime dependence semantics by example.
6264
public struct Span<T>: ~Escapable {
6365
private var base: UnsafePointer<T>?
@@ -275,6 +277,14 @@ struct Container<T> {
275277
let count: Int
276278
}
277279

280+
// Dependence on an empty initialized value should be scoped to variable decl.
281+
@lifetime(copy x)
282+
func f(x: NotEscapable) -> NotEscapable {
283+
let local = NotEscapable() // expected-error {{lifetime-dependent variable 'local' escapes its scope}}
284+
// expected-note @-1{{it depends on the lifetime of this parent value}}
285+
return local // expected-note {{this use causes the lifetime-dependent value to escape}}
286+
}
287+
278288
// =============================================================================
279289
// Scoped dependence on values
280290
// =============================================================================

0 commit comments

Comments
 (0)