Skip to content

Commit f716c09

Browse files
committed
Diagnose if lifetime dependence specifier is present on Escapable type
1 parent 24d6a29 commit f716c09

File tree

3 files changed

+4
-8
lines changed

3 files changed

+4
-8
lines changed

include/swift/AST/DiagnosticsSema.def

+1-2
Original file line numberDiff line numberDiff line change
@@ -7807,8 +7807,7 @@ ERROR(pack_iteration_where_clause_not_supported, none,
78077807
"functions, methods, initializers",
78087808
())
78097809
ERROR(lifetime_dependence_invalid_return_type, none,
7810-
"lifetime dependence specifiers can only be specifier on ~Escapable "
7811-
"results", ())
7810+
"lifetime dependence can only be specified on ~Escapable results", ())
78127811
ERROR(lifetime_dependence_missing_ownership_modifier, none,
78137812
"lifetime dependence can only be specified on parameters with ownership "
78147813
"modifiers (borrowing, consuming, inout)", ())

lib/Sema/TypeCheckDecl.cpp

+2-5
Original file line numberDiff line numberDiff line change
@@ -2592,14 +2592,11 @@ llvm::Optional<LifetimeDependenceInfo> validateLifetimeDependenceInfo(
25922592
auto loc = specifier.getLoc();
25932593
auto kind = specifier.getLifetimeDependenceKind();
25942594

2595-
/* TODO: Enable this
2596-
if (TypeChecker::conformsToKnownProtocol(resultTy,
2597-
InvertibleProtocolKind::Escapable,
2598-
dc->getParentModule())) {
2595+
if (resultTy->isEscapable()) {
25992596
diags.diagnose(loc, diag::lifetime_dependence_invalid_return_type);
26002597
return true;
26012598
}
2602-
*/
2599+
26032600
if (ownership == ValueOwnership::Default) {
26042601
diags.diagnose(loc, diag::lifetime_dependence_missing_ownership_modifier);
26052602
return true;

test/Sema/explicit_lifetime_dependence_specifiers.swift

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct WrapperStruct {
2222
let k: Klass
2323
}
2424

25-
func invalidLifetimeDependenceOnEscapable(_ w: borrowing WrapperStruct) -> Klass {
25+
func invalidLifetimeDependenceOnEscapableResult(_ w: borrowing WrapperStruct) -> _borrow(w) Klass { // expected-error{{lifetime dependence can only be specified on ~Escapable results}}
2626
return w.k
2727
}
2828

0 commit comments

Comments
 (0)