@@ -1021,7 +1021,8 @@ class LifetimeDependenceChecker {
1021
1021
}
1022
1022
1023
1023
bool nonEscapableSelf = isDiagnosedNonEscapable (selfTypeInContext);
1024
- if (auto accessor = dyn_cast<AccessorDecl>(afd)) {
1024
+ auto accessor = dyn_cast<AccessorDecl>(afd);
1025
+ if (accessor) {
1025
1026
if (isImplicitOrSIL () || useLazyInference ()) {
1026
1027
if (nonEscapableSelf && afd->getImplicitSelfDecl ()->isInOut ()) {
1027
1028
// Implicit accessors that return or yield a non-Escapable value may
@@ -1038,14 +1039,18 @@ class LifetimeDependenceChecker {
1038
1039
}
1039
1040
// Explicit accessors are inferred the same way as regular methods.
1040
1041
}
1041
- // Do infer the result of a mutating method when 'self' is
1042
- // non-Escapable. The missing dependence on inout 'self' will be diagnosed
1043
- // later anyway, so an explicit annotation will still be needed.
1042
+ // Do not infer the result's dependence when the method is mutating and
1043
+ // 'self' is non-Escapable. Independently, a missing dependence on inout
1044
+ // 'self' will be diagnosed. Since an explicit annotation will be needed for
1045
+ // 'self', we also require the method's result to have an explicit
1046
+ // annotation.
1044
1047
if (nonEscapableSelf && afd->getImplicitSelfDecl ()->isInOut ()) {
1045
1048
return ;
1046
1049
}
1047
- // Methods with parameters only apply to lazy inference.
1048
- if (!useLazyInference () && afd->getParameters ()->size () > 0 ) {
1050
+ // Methods with parameters only apply to lazy inference. This does not
1051
+ // include accessors because a subscript's index is assumed not to be the
1052
+ // source of the result's dependency.
1053
+ if (!accessor && !useLazyInference () && afd->getParameters ()->size () > 0 ) {
1049
1054
return ;
1050
1055
}
1051
1056
if (!useLazyInference () && !isImplicitOrSIL ()) {
@@ -1388,7 +1393,7 @@ class LifetimeDependenceChecker {
1388
1393
return std::nullopt;
1389
1394
}
1390
1395
if (wrappedAccessorKind) {
1391
- auto *var = cast<VarDecl >(accessor->getStorage ());
1396
+ auto *var = cast<AbstractStorageDecl >(accessor->getStorage ());
1392
1397
for (auto *wrappedAccessor : var->getAllAccessors ()) {
1393
1398
if (wrappedAccessor->isImplicit ())
1394
1399
continue ;
0 commit comments