Skip to content

Commit 746c808

Browse files
authored
Merge pull request #76711 from xedin/rdar-133403333
[Concurrency] Allow properties with `@Sendable` function types witnes…
2 parents cf81f05 + f8f7db3 commit 746c808

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,7 +885,25 @@ RequirementMatch swift::matchWitness(
885885
if (!req->isObjC() && reqTypeIsIUO != witnessTypeIsIUO)
886886
return RequirementMatch(witness, MatchKind::TypeConflict, witnessType);
887887

888-
if (auto result = matchTypes(std::get<0>(types), std::get<1>(types))) {
888+
auto reqType = std::get<0>(types);
889+
auto witnessType = std::get<1>(types);
890+
891+
// Allow witnesses with @Sendable types to match non-Sendable requirements.
892+
// This is already supported for method and subscript witnesses that get
893+
// their types decomposed.
894+
if (auto *reqFnType = reqType->getAs<AnyFunctionType>()) {
895+
if (auto *witnessFnType = witnessType->getAs<AnyFunctionType>()) {
896+
if (reqFnType->hasExtInfo() && witnessFnType->hasExtInfo()) {
897+
auto reqExtInfo = reqFnType->getExtInfo();
898+
auto witnessExtInfo = witnessFnType->getExtInfo();
899+
900+
if (!reqExtInfo.isSendable() && witnessExtInfo.isSendable())
901+
reqType = reqFnType->withExtInfo(reqExtInfo.withSendable());
902+
}
903+
}
904+
}
905+
906+
if (auto result = matchTypes(reqType, witnessType)) {
889907
return std::move(result.value());
890908
}
891909
}

test/Concurrency/sendable_conformance_checking.swift

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,3 +187,20 @@ actor MyActor {
187187
// expected-warning@+1 {{non-final class 'Nested' cannot conform to 'Sendable'; use '@unchecked Sendable'; this is an error in the Swift 6 language mode}}
188188
class Nested: Sendable {}
189189
}
190+
191+
@Sendable func globalFn() {}
192+
193+
protocol NoSendableReqs {
194+
var prop: () -> Void { get }
195+
static var staticProp: () -> Void { get }
196+
}
197+
198+
public struct TestSendableWitnesses1 : NoSendableReqs {
199+
var prop: @Sendable () -> Void // Ok (no warnings)
200+
static let staticProp: @Sendable () -> Void = { } // Ok (no warnings)
201+
}
202+
203+
public struct TestSendableWitnesses2 : NoSendableReqs {
204+
var prop = globalFn // Ok (no warnings)
205+
static let staticProp = globalFn // Ok (no warnings)
206+
}

0 commit comments

Comments
 (0)