Skip to content

Commit 6c1fc03

Browse files
committed
[TypeChecker] Limit sendability downgrade to preconcurrency requirements only
1 parent 9a3d1b7 commit 6c1fc03

File tree

4 files changed

+26
-6
lines changed

4 files changed

+26
-6
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5619,6 +5619,7 @@ bool ConstraintSystem::repairFailures(
56195619
// Matching a witness to an protocol requirement.
56205620
if (isa<ProtocolDecl>(VD->getDeclContext()) &&
56215621
VD->isProtocolRequirement() &&
5622+
VD->preconcurrency() &&
56225623
path[0].is<LocatorPathElt::Witness>() &&
56235624
// Note that the condition below is very important,
56245625
// we need to wait until the very last moment to strip

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,9 +1261,12 @@ swift::matchWitness(WitnessChecker::RequirementEnvironmentCache &reqEnvCache,
12611261

12621262
// If there are no other issues, let's check whether this are
12631263
// missing Sendable conformances when matching ObjC requirements.
1264-
// This is not an error until Swift 6 because `swift_attr` wasn't
1265-
// allowed in type contexts initially.
1266-
return solution->getFixedScore()
1264+
// This is not an error until Swift 6 because i.e. `swift_attr` wasn't
1265+
// allowed in type contexts initially and introducing new concurrency
1266+
// attributes shouldn't break witnesses without strict concurrency
1267+
// enabled.
1268+
return req->preconcurrency() &&
1269+
solution->getFixedScore()
12671270
.Data[SK_MissingSynthesizableConformance] > 0;
12681271
}();
12691272

test/Concurrency/witness_matching_with_sendable.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
// RUN: %target-typecheck-verify-swift -swift-version 6 -verify-additional-prefix swift6-
44

55
protocol P {
6-
var prop: [String: any Sendable] { get set }
6+
@preconcurrency var prop: [String: any Sendable] { get set }
77
// expected-swift5-note@-1 3 {{expected sendability to match requirement here}}
88
// expected-swift6-note@-2 3 {{protocol requires property 'prop' with type '[String : any Sendable]'}}
9-
func reqFn(_: [String: any Sendable], _: @Sendable ((any Sendable)?) -> Void)
9+
@preconcurrency func reqFn(_: [String: any Sendable], _: @Sendable ((any Sendable)?) -> Void)
1010
// expected-swift5-note@-1 2 {{expected sendability to match requirement here}}
1111
// expected-swift6-note@-2 2 {{protocol requires function 'reqFn' with type '([String : any Sendable], @Sendable ((any Sendable)?) -> Void) -> ()'}}
1212
}
@@ -37,3 +37,19 @@ struct S3 : P { // expected-swift6-error {{type 'S3' does not conform to protoco
3737

3838
func reqFn(_: [String: any Sendable], _: ((any Sendable)?) -> Void) {} // Ok
3939
}
40+
41+
protocol Q {
42+
var prop: [String: [String: any Sendable]] { get set }
43+
// expected-note@-1 {{protocol requires property 'prop' with type '[String : [String : any Sendable]]'}}
44+
45+
func test(_: [() -> (any Sendable)?])
46+
// expected-note@-1 {{protocol requires function 'test' with type '([() -> (any Sendable)?]) -> ()'}}
47+
}
48+
49+
struct S4 : Q { // expected-error {{type 'S4' does not conform to protocol 'Q'}} expected-note {{add stubs for conformance}}
50+
var prop: [String: [String: Any]] = [:]
51+
// expected-note@-1 {{candidate has non-matching type '[String : [String : Any]]'}}
52+
53+
func test(_: [() -> Any?]) {}
54+
// expected-note@-1 {{candidate has non-matching type '([() -> Any?]) -> ()'}}
55+
}

test/decl/protocol/conforms/isolated_any.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -typecheck -verify -swift-version 6 %s
1+
// RUN: %target-swift-frontend -typecheck -verify %s
22

33
struct A<T> {
44
// expected-note @+1 {{candidate has non-matching type}}

0 commit comments

Comments
 (0)