Skip to content

[6.2] Fix a lifetime dependence diagnostic #82810

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 7, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -8249,7 +8249,7 @@ ERROR(lifetime_dependence_cannot_use_parsed_borrow_inout, none,
ERROR(lifetime_dependence_duplicate_target, none,
"invalid duplicate target lifetime dependencies on function", ())
ERROR(lifetime_parameter_requires_inout, none,
"lifetime-dependent parameter must be 'inout'", (Identifier))
"lifetime-dependent parameter '%0' must be 'inout'", (StringRef))

//------------------------------------------------------------------------------
// MARK: Lifetime Dependence Requirements
Expand Down
2 changes: 1 addition & 1 deletion lib/AST/LifetimeDependence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ class LifetimeDependenceChecker {
if (!targetDeclAndIndex->first->isInOut()) {
diagnose(targetDeclAndIndex->first,
diag::lifetime_parameter_requires_inout,
targetDescriptor->getName());
targetDescriptor->getString());
}
targetIndex = targetDeclAndIndex->second;
} else {
Expand Down
15 changes: 14 additions & 1 deletion test/Sema/lifetime_attr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ do {

// rdar://146401190 ([nonescapable] implement non-inout parameter dependencies)
@_lifetime(span: borrow holder)
func testParameterDep(holder: AnyObject, span: Span<Int>) {} // expected-error{{lifetime-dependent parameter must be 'inout'}}
func testParameterDep(holder: AnyObject, span: Span<Int>) {} // expected-error{{lifetime-dependent parameter 'span' must be 'inout'}}

@_lifetime(&ne)
func inoutLifetimeDependence(_ ne: inout NE) -> NE {
Expand All @@ -113,3 +113,16 @@ func dependOnEscapable(_ k: consuming Klass) -> NE {
NE()
}

struct Wrapper : ~Escapable {
var _ne: NE

var ne: NE {
@_lifetime(copy self)
get {
_ne
}
@_lifetime(self: &self)
nonmutating _modify {// expected-error{{lifetime-dependent parameter 'self' must be 'inout'}}
}
}
}