Skip to content

Commit 044716d

Browse files
committed
Put function and subcript check in one
1 parent 72a211f commit 044716d

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
@@ -1160,12 +1160,21 @@ bool swift::diagnoseNonSendableTypesInReference(
11601160
return true;
11611161
}
11621162

1163-
// For functions, check the parameter and result types.
1163+
// For functions or subscripts, check the parameter and result types.
11641164
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)) {
11661167
if (funcCheckOptions.contains(FunctionCheckKind::Params)) {
11671168
// 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) {
11691178
Type paramType = param->getInterfaceType().subst(subs);
11701179
if (param->isSending() && !paramType->hasError()) {
11711180
continue;
@@ -1175,13 +1184,13 @@ bool swift::diagnoseNonSendableTypesInReference(
11751184
paramType, fromDC, derivedConformanceType,
11761185
refLoc, diagnoseLoc.isInvalid() ? refLoc : diagnoseLoc,
11771186
getSendableParamDiag(refKind),
1178-
function, getActorIsolation()))
1187+
decl, getActorIsolation()))
11791188
return true;
11801189
}
11811190
}
11821191

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)) {
11851194
if (funcCheckOptions.contains(FunctionCheckKind::Results)) {
11861195
// only check results if funcCheckKind specifies so
11871196
Type resultType = func->getResultInterfaceType().subst(subs);
@@ -1213,34 +1222,6 @@ bool swift::diagnoseNonSendableTypesInReference(
12131222
return true;
12141223
}
12151224

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-
12441225
return false;
12451226
}
12461227

0 commit comments

Comments
 (0)