Skip to content

Commit fbf5524

Browse files
committed
Put function and subcript check in one
1 parent 47b16f5 commit fbf5524

File tree

1 file changed

+15
-34
lines changed

1 file changed

+15
-34
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,12 +1168,21 @@ bool swift::diagnoseNonSendableTypesInReference(
11681168
return true;
11691169
}
11701170

1171-
// For functions, check the parameter and result types.
1171+
// For functions or subscripts, check the parameter and result types.
11721172
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)) {
11741175
if (funcCheckOptions.contains(FunctionCheckKind::Params)) {
11751176
// 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) {
11771186
Type paramType = param->getInterfaceType().subst(subs);
11781187
if (param->isSending() && !paramType->hasError()) {
11791188
continue;
@@ -1183,13 +1192,13 @@ bool swift::diagnoseNonSendableTypesInReference(
11831192
paramType, fromDC, derivedConformanceType,
11841193
refLoc, diagnoseLoc.isInvalid() ? refLoc : diagnoseLoc,
11851194
getSendableParamDiag(refKind),
1186-
function, getActorIsolation()))
1195+
decl, getActorIsolation()))
11871196
return true;
11881197
}
11891198
}
11901199

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)) {
11931202
if (funcCheckOptions.contains(FunctionCheckKind::Results)) {
11941203
// only check results if funcCheckKind specifies so
11951204
Type resultType = func->getResultInterfaceType().subst(subs);
@@ -1221,34 +1230,6 @@ bool swift::diagnoseNonSendableTypesInReference(
12211230
return true;
12221231
}
12231232

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-
12521233
return false;
12531234
}
12541235

0 commit comments

Comments
 (0)