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