Skip to content

Commit deb920e

Browse files
committed
[NFC] lifetime inference: check for prior defaults before error
Don't diagnose a lifetime error if a previous default already handled the non-Escapable output in question.
1 parent 43ca0bf commit deb920e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/AST/LifetimeDependence.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1117,7 +1117,8 @@ class LifetimeDependenceChecker {
11171117
bool nonEscapableSelf = isDiagnosedNonEscapable(dc->getSelfTypeInContext());
11181118
if (nonEscapableSelf && accessor->getImplicitSelfDecl()->isInOut()) {
11191119
// First, infer the dependency of the inout non-Escapable 'self'. This may
1120-
// result in two inferred dependencies for accessors.
1120+
// result in two inferred dependencies for accessors (one targetting
1121+
// selfIndex here, and one targetting resultIndex below).
11211122
inferMutatingAccessor(accessor);
11221123
}
11231124
// Handle synthesized wrappers...
@@ -1255,6 +1256,9 @@ class LifetimeDependenceChecker {
12551256
if (!resultDeps)
12561257
return; // .sil implicit initializers may have been annotated.
12571258

1259+
if (!resultDeps->empty())
1260+
return; // same-type inferrence applied; don't issue diagnostics.
1261+
12581262
unsigned paramIndex = 0;
12591263
for (auto *param : *afd->getParameters()) {
12601264
SWIFT_DEFER { paramIndex++; };
@@ -1293,6 +1297,9 @@ class LifetimeDependenceChecker {
12931297
if (!resultDeps)
12941298
return;
12951299

1300+
if (!resultDeps->empty())
1301+
return; // same-type inferrence applied; don't issue diagnostics.
1302+
12961303
bool nonEscapableSelf = isDiagnosedNonEscapable(dc->getSelfTypeInContext());
12971304
// Do not infer the result's dependence when the method is mutating and
12981305
// 'self' is non-Escapable. Independently, a missing dependence on inout
@@ -1359,6 +1366,9 @@ class LifetimeDependenceChecker {
13591366
if (!resultDeps)
13601367
return;
13611368

1369+
if (!resultDeps->empty())
1370+
return; // same-type inferrence applied; don't issue diagnostics.
1371+
13621372
// Strict inference only handles a single escapable parameter,
13631373
// which is an unambiguous borrow dependence.
13641374
if (afd->getParameters()->size() == 0) {

0 commit comments

Comments
 (0)