Skip to content

Commit 84d775e

Browse files
committed
[Concurrency] TildeSendable: Account for inherited conformances
This helps to properly detect and account for derived conformances to `Sendable` protocol that come from parent classes.
1 parent d8860bc commit 84d775e

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

lib/Sema/TypeCheckConcurrency.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7378,6 +7378,12 @@ bool swift::checkSendableConformance(
73787378
// Sendable supression allows conditional conformances only.
73797379
if (nominal->suppressesConformance(KnownProtocolKind::Sendable)) {
73807380
bool hasUnconditionalConformance = false;
7381+
7382+
if (auto *inherited = dyn_cast<InheritedProtocolConformance>(conformance)) {
7383+
hasUnconditionalConformance =
7384+
inherited->getConditionalRequirements().empty();
7385+
}
7386+
73817387
if (auto *normalConf = dyn_cast<NormalProtocolConformance>(conformance)) {
73827388
hasUnconditionalConformance =
73837389
normalConf->getConditionalRequirements().empty();

test/Sema/tilde_sendable.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,4 +119,16 @@ do {
119119

120120
testSendable(IsolatedC())
121121
// expected-warning@-1 {{type 'IsolatedC' does not conform to the 'Sendable' protocol}}
122+
123+
@MainActor
124+
class IsolatedBase {} // derived as Sendable
125+
126+
class Child1: IsolatedBase, ~Sendable {}
127+
// expected-error@-1 {{cannot both conform to and suppress conformance to 'Sendable'}}
128+
129+
class Base: Sendable {}
130+
// expected-warning@-1 {{non-final class 'Base' cannot conform to the 'Sendable' protocol}}
131+
132+
class Child2: Base, ~Sendable {}
133+
// expected-error@-1 {{cannot both conform to and suppress conformance to 'Sendable'}}
122134
}

0 commit comments

Comments
 (0)