Skip to content

Commit ad87a5c

Browse files
committed
[Concurrency] Downgrade error about inherited Sendable classes inheriting from non-NSObject to warning
1 parent e6a6ecf commit ad87a5c

File tree

2 files changed

+44
-5
lines changed

2 files changed

+44
-5
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5110,11 +5110,14 @@ bool swift::checkSendableConformance(
51105110
// we allow `NSObject` for Objective-C interoperability.
51115111
if (auto superclassDecl = classDecl->getSuperclassDecl()) {
51125112
if (!superclassDecl->isNSObject()) {
5113-
classDecl->diagnose(
5114-
diag::concurrent_value_inherit,
5115-
nominal->getASTContext().LangOpts.EnableObjCInterop,
5116-
classDecl->getName());
5117-
return true;
5113+
classDecl
5114+
->diagnose(diag::concurrent_value_inherit,
5115+
nominal->getASTContext().LangOpts.EnableObjCInterop,
5116+
classDecl->getName())
5117+
.limitBehavior(behavior);
5118+
5119+
if (behavior == DiagnosticBehavior::Unspecified)
5120+
return true;
51185121
}
51195122
}
51205123
}

test/Concurrency/sendable_objc_protocol_attr.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,42 @@ class KUncheckedRefined : NSObject, MyRefinedObjCProtocol, @unchecked Sendable {
6060
let test: String = "refined unchecked"
6161
}
6262

63+
@preconcurrency
64+
protocol P : Sendable {
65+
}
66+
67+
protocol Q : Sendable {
68+
}
69+
70+
do {
71+
class A : NSObject {}
72+
73+
final class B : A, P {
74+
// expected-warning@-1 {{'Sendable' class 'B' cannot inherit from another class other than 'NSObject'}}
75+
}
76+
77+
final class UncheckedB : A, P, @unchecked Sendable { // Ok
78+
}
79+
80+
class C : A, MyObjCProtocol {
81+
// expected-warning@-1 {{non-final class 'C' cannot conform to 'Sendable'; use '@unchecked Sendable'}}
82+
// expected-warning@-2 {{'Sendable' class 'C' cannot inherit from another class other than 'NSObject'}}
83+
let test: String = "c"
84+
}
85+
86+
class UncheckedC : A, MyObjCProtocol, @unchecked Sendable { // Ok
87+
let test: String = "c"
88+
}
89+
90+
// A warning until `-swift-version 6`
91+
final class D : A, Q {
92+
// expected-warning@-1 {{'Sendable' class 'D' cannot inherit from another class other than 'NSObject'}}
93+
}
94+
95+
final class UncheckedD : A, Q, @unchecked Sendable { // Ok
96+
}
97+
}
98+
6399
do {
64100
func testSendable<T: Sendable>(_: T) {}
65101

0 commit comments

Comments
 (0)