Skip to content

Commit 59c071a

Browse files
committed
Fix subscript check and add test for sending result in subscript
1 parent d5b3d04 commit 59c071a

File tree

2 files changed

+37
-14
lines changed

2 files changed

+37
-14
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,21 +1197,30 @@ bool swift::diagnoseNonSendableTypesInReference(
11971197
}
11981198

11991199
// Check the result type of a function or subscript.
1200-
if (auto func = dyn_cast<FuncDecl>(decl)) {
1201-
if (funcCheckOptions.contains(FunctionCheckKind::Results)) {
1202-
// only check results if funcCheckKind specifies so
1203-
Type resultType = func->getResultInterfaceType().subst(subs);
1204-
auto diag = getSendableResultDiag(refKind);
1205-
if (diag.ID == diag::non_sendable_result_in_witness.ID &&
1206-
func->hasSendingResult() && !resultType->hasError()) {
1207-
return false;
1208-
}
1209-
if (diagnoseNonSendableTypes(
1210-
resultType, fromDC, derivedConformanceType, refLoc,
1211-
diagnoseLoc.isInvalid() ? refLoc : diagnoseLoc, diag, func,
1212-
getActorIsolation()))
1213-
return true;
1200+
if (funcCheckOptions.contains(FunctionCheckKind::Results)) {
1201+
Type resultType;
1202+
bool hasSendingResult;
1203+
if (auto func = dyn_cast<FuncDecl>(decl)) {
1204+
resultType = func->getResultInterfaceType().subst(subs);
1205+
hasSendingResult = func->hasSendingResult();
1206+
decl = func;
1207+
} else if (auto subscript = dyn_cast<SubscriptDecl>(decl)) {
1208+
resultType = subscript->getElementInterfaceType().subst(subs);
1209+
hasSendingResult = isa<SendingTypeRepr>(subscript->getResultTypeRepr());
12141210
}
1211+
if (!resultType) {
1212+
return false;
1213+
}
1214+
auto diag = getSendableResultDiag(refKind);
1215+
if (diag.ID == diag::non_sendable_result_in_witness.ID &&
1216+
hasSendingResult && !resultType->hasError()) {
1217+
return false;
1218+
}
1219+
if (diagnoseNonSendableTypes(
1220+
resultType, fromDC, derivedConformanceType, refLoc,
1221+
diagnoseLoc.isInvalid() ? refLoc : diagnoseLoc, diag, decl,
1222+
getActorIsolation()))
1223+
return true;
12151224
}
12161225

12171226
return false;

test/Concurrency/sendable_conformance_checking_skip_sending.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,17 @@ protocol P6 {
7474
class P6Class: P6 {
7575
func bar(_ a: sending NonSendableKlass6, _ b: sending NonSendableKlass6) async -> sending NonSendableKlass6 { a }
7676
}
77+
78+
class NonSendableKlass7 {}
79+
80+
protocol P7 {
81+
subscript(_: sending NonSendableKlass7) -> sending NonSendableKlass7 { get async }
82+
}
83+
84+
@MainActor
85+
struct S: P7 {
86+
subscript(_: sending NonSendableKlass7) -> sending NonSendableKlass7 {
87+
get async { NonSendableKlass7() }
88+
}
89+
}
90+

0 commit comments

Comments
 (0)