Skip to content

Commit f13904b

Browse files
authored
Merge pull request #71889 from xedin/static-members-are-always-sendable
[ConstraintSystem] Skip sendability check for static members
2 parents e2c94ad + 7c0bb41 commit f13904b

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
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/predates_concurrency_swift6.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ func testInAsync(x: X) async {
2929
let _: Int = unsafelyMainActorClosure // expected-error{{type '@Sendable (@MainActor () -> Void) -> ()'}}
3030
let _: Int = unsafelyDoEverythingClosure // expected-error{{type '@Sendable (@MainActor @Sendable () -> Void) -> ()'}}
3131
let _: Int = x.unsafelyDoEverythingClosure // expected-error{{type '(@MainActor @Sendable () -> Void) -> ()'}}
32-
let _: Int = X.unsafelyDoEverythingClosure // expected-error{{type '@Sendable (X) -> (@MainActor @Sendable () -> Void) -> ()'}}
33-
let _: Int = (X.unsafelyDoEverythingClosure)(x) // expected-error{{type '(@MainActor @Sendable () -> Void) -> ()'}}
32+
let _: Int = X.unsafelyDoEverythingClosure // expected-error{{type '@Sendable (X) -> @Sendable (@MainActor @Sendable () -> Void) -> ()'}}
33+
let _: Int = (X.unsafelyDoEverythingClosure)(x) // expected-error{{type '@Sendable (@MainActor @Sendable () -> Void) -> ()'}}
3434

3535
let _: Int = x.sendableVar // expected-error{{type '@Sendable () -> Void'}}
3636
let _: Int = x.mainActorVar // expected-error{{type '@MainActor () -> Void'}}
@@ -44,8 +44,8 @@ func testElsewhere(x: X) {
4444
let _: Int = unsafelyMainActorClosure // expected-error{{type '@Sendable (@MainActor () -> Void) -> ()'}}
4545
let _: Int = unsafelyDoEverythingClosure // expected-error{{type '@Sendable (@MainActor @Sendable () -> Void) -> ()'}}
4646
let _: Int = x.unsafelyDoEverythingClosure // expected-error{{type '(@MainActor @Sendable () -> Void) -> ()'}}
47-
let _: Int = X.unsafelyDoEverythingClosure // expected-error{{type '@Sendable (X) -> (@MainActor @Sendable () -> Void) -> ()'}}
48-
let _: Int = (X.unsafelyDoEverythingClosure)(x) // expected-error{{type '(@MainActor @Sendable () -> Void) -> ()'}}
47+
let _: Int = X.unsafelyDoEverythingClosure // expected-error{{type '@Sendable (X) -> @Sendable (@MainActor @Sendable () -> Void) -> ()'}}
48+
let _: Int = (X.unsafelyDoEverythingClosure)(x) // expected-error{{type '@Sendable (@MainActor @Sendable () -> Void) -> ()'}}
4949

5050
let _: Int = x.sendableVar // expected-error{{type '@Sendable () -> Void'}}
5151
let _: Int = x.mainActorVar // expected-error{{type '@MainActor () -> Void'}}

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 {{converting 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 {{converting non-sendable function value to '@Sendable (Int, Int) -> Array<Int>' may introduce data races}}
64+
}

0 commit comments

Comments
 (0)