@@ -1160,12 +1160,21 @@ bool swift::diagnoseNonSendableTypesInReference(
1160
1160
return true ;
1161
1161
}
1162
1162
1163
- // For functions, check the parameter and result types.
1163
+ // For functions or subscripts , check the parameter and result types.
1164
1164
SubstitutionMap subs = declRef.getSubstitutions ();
1165
- if (auto function = dyn_cast<AbstractFunctionDecl>(declRef.getDecl ())) {
1165
+ auto decl = declRef.getDecl ();
1166
+ if (isa<AbstractFunctionDecl>(decl) || isa<SubscriptDecl>(decl)) {
1166
1167
if (funcCheckOptions.contains (FunctionCheckKind::Params)) {
1167
1168
// only check params if funcCheckKind specifies so
1168
- for (auto param : *function->getParameters ()) {
1169
+ ParameterList *paramList = nullptr ;
1170
+ if (auto function = dyn_cast<AbstractFunctionDecl>(decl)) {
1171
+ paramList = function->getParameters ();
1172
+ } else if (auto subscript = dyn_cast<SubscriptDecl>(decl)) {
1173
+ paramList = subscript->getIndices ();
1174
+ }
1175
+
1176
+ // Check params of this function or subscript override for sendability
1177
+ for (auto param : *paramList) {
1169
1178
Type paramType = param->getInterfaceType ().subst (subs);
1170
1179
if (param->isSending () && !paramType->hasError ()) {
1171
1180
continue ;
@@ -1175,13 +1184,13 @@ bool swift::diagnoseNonSendableTypesInReference(
1175
1184
paramType, fromDC, derivedConformanceType,
1176
1185
refLoc, diagnoseLoc.isInvalid () ? refLoc : diagnoseLoc,
1177
1186
getSendableParamDiag (refKind),
1178
- function , getActorIsolation ()))
1187
+ decl , getActorIsolation ()))
1179
1188
return true ;
1180
1189
}
1181
1190
}
1182
1191
1183
- // Check the result type of a function.
1184
- if (auto func = dyn_cast<FuncDecl>(function )) {
1192
+ // Check the result type of a function or subscript .
1193
+ if (auto func = dyn_cast<FuncDecl>(decl )) {
1185
1194
if (funcCheckOptions.contains (FunctionCheckKind::Results)) {
1186
1195
// only check results if funcCheckKind specifies so
1187
1196
Type resultType = func->getResultInterfaceType ().subst (subs);
@@ -1213,34 +1222,6 @@ bool swift::diagnoseNonSendableTypesInReference(
1213
1222
return true ;
1214
1223
}
1215
1224
1216
- if (auto subscript = dyn_cast<SubscriptDecl>(declRef.getDecl ())) {
1217
- for (auto param : *subscript->getIndices ()) {
1218
- if (funcCheckOptions.contains (FunctionCheckKind::Params)) {
1219
- // Check params of this subscript override for sendability
1220
- Type paramType = param->getInterfaceType ().subst (subs);
1221
- if (diagnoseNonSendableTypes (
1222
- paramType, fromDC, derivedConformanceType,
1223
- refLoc, diagnoseLoc.isInvalid () ? refLoc : diagnoseLoc,
1224
- getSendableParamDiag (refKind),
1225
- subscript, getActorIsolation ()))
1226
- return true ;
1227
- }
1228
- }
1229
-
1230
- if (funcCheckOptions.contains (FunctionCheckKind::Results)) {
1231
- // Check the element type of a subscript.
1232
- Type resultType = subscript->getElementInterfaceType ().subst (subs);
1233
- if (diagnoseNonSendableTypes (
1234
- resultType, fromDC, derivedConformanceType,
1235
- refLoc, diagnoseLoc.isInvalid () ? refLoc : diagnoseLoc,
1236
- getSendableResultDiag (refKind),
1237
- subscript, getActorIsolation ()))
1238
- return true ;
1239
- }
1240
-
1241
- return false ;
1242
- }
1243
-
1244
1225
return false ;
1245
1226
}
1246
1227
0 commit comments