Skip to content

Commit 10a5f0c

Browse files
committed
Add tests for basic LifetimeDependence requirements
Test each basic case that requires LifetimeDependences, first without enabling the LifetimeDependence feature, then without specifying the kind of dependence.
1 parent edaf04b commit 10a5f0c

File tree

2 files changed

+64
-0
lines changed

2 files changed

+64
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %target-swift-frontend %s -emit-sil \
2+
// RUN: -o /dev/null \
3+
// RUN: -verify \
4+
// RUN: -sil-verify-all \
5+
// RUN: -disable-availability-checking \
6+
// RUN: -module-name test \
7+
// RUN: -enable-experimental-feature LifetimeDependence
8+
9+
// REQUIRES: swift_feature_LifetimeDependence
10+
11+
// These tests complement lifetime_depend_nofeature.swift. If you add a test here, add one there.
12+
13+
// Check that missing lifetime dependencies are diagnosed. Enabling LifetimeDependencies will issue more detailed
14+
// diagnostics.
15+
16+
// Allow empty initialization.
17+
struct EmptyNonEscapable: ~Escapable {} // OK - no dependence
18+
19+
// Don't allow non-Escapable return values.
20+
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{cannot infer the lifetime dependence scope on a function with a ~Escapable parameter, specify '@lifetime(borrow span)' or '@lifetime(copy span)'}}
21+
22+
func neInout(span: inout RawSpan) {} // OK - inferred
23+
24+
struct S {
25+
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{a method with a ~Escapable result requires '@lifetime(...)}}
26+
27+
func neInout(span: inout RawSpan) {} // OK - inferred
28+
}
29+
30+
class C {
31+
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{a method with a ~Escapable result requires '@lifetime(...)'}}
32+
33+
func neInout(span: inout RawSpan) {} // OK - inferred
34+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// RUN: %target-swift-frontend %s -emit-sil \
2+
// RUN: -o /dev/null \
3+
// RUN: -verify \
4+
// RUN: -sil-verify-all \
5+
// RUN: -disable-availability-checking \
6+
// RUN: -module-name test
7+
8+
// These tests complement lifetime_depend_noattr.swift. If you add a test here, add one there.
9+
10+
// Check that functions that require lifetime dependence are prohibited without the flag.
11+
12+
// Don't allow empty initialization.
13+
struct EmptyNonEscapable: ~Escapable {} // expected-error{{an implicit initializer with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'}}
14+
15+
// Don't allow non-Escapable return values.
16+
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{a function with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'}}
17+
18+
func neInout(span: inout RawSpan) {} // expected-error{{a function with a ~Escapable 'inout' parameter requires '-enable-experimental-feature LifetimeDependence'}}
19+
20+
struct S {
21+
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{a method with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'}}
22+
23+
func neInout(span: inout RawSpan) {} // expected-error{{a method with a ~Escapable 'inout' parameter requires '-enable-experimental-feature LifetimeDependence'}}
24+
}
25+
26+
class C {
27+
func neReturn(span: RawSpan) -> RawSpan { span } // expected-error{{a method with a ~Escapable result requires '-enable-experimental-feature LifetimeDependence'}}
28+
29+
func neInout(span: inout RawSpan) {} // expected-error{{a method with a ~Escapable 'inout' parameter requires '-enable-experimental-feature LifetimeDependence'}}
30+
}

0 commit comments

Comments
 (0)