Skip to content

Commit 25dfce4

Browse files
committed
[ConstraintSystem] Skip sendability check for static members
Such members only capture base metatatypes which are themselves always sendable.
1 parent 03194eb commit 25dfce4

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/Sema/ConstraintSystem.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2806,7 +2806,9 @@ ConstraintSystem::getTypeOfMemberReference(
28062806
FunctionType::ExtInfo info;
28072807

28082808
if (Context.LangOpts.hasFeature(Feature::InferSendableFromCaptures)) {
2809-
if (isPartialApplication(locator) && baseOpenedTy->isSendableType()) {
2809+
if (isPartialApplication(locator) &&
2810+
(resolvedBaseTy->is<AnyMetatypeType>() ||
2811+
baseOpenedTy->isSendableType())) {
28102812
// Add @Sendable to functions without conditional conformances
28112813
functionType =
28122814
functionType

test/Concurrency/sendable_functions.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,19 @@ extension S: Sendable where T: Sendable {
4646

4747
@available(SwiftStdlib 5.1, *)
4848
@MainActor @Sendable func globalActorFuncAsync() async { }
49+
50+
func test_initializer_ref() {
51+
func test<T>(_: @Sendable (T, T) -> Array<T>) {
52+
}
53+
54+
// Type of `initRef` should be @Sendable but due to implicitly injected autoclosure it isn't
55+
let initRef = Array.init as (Int, Int) -> Array<Int>
56+
57+
// FIXME: incorrect non-Sendable diagnostic is produced due to `autoclosure` wrapping `Array.init`
58+
test(initRef)
59+
// expected-warning@-1 {{onverting non-sendable function value to '@Sendable (Int, Int) -> Array<Int>' may introduce data races}}
60+
61+
// FIXME: Same here
62+
test(Array.init as (Int, Int) -> Array<Int>)
63+
// expected-warning@-1 {{onverting non-sendable function value to '@Sendable (Int, Int) -> Array<Int>' may introduce data races}}
64+
}

0 commit comments

Comments
 (0)