Skip to content

Commit fc58596

Browse files
committed
Don't allow missing conformances from superclasses to block Sendable subclasses
Fixes rdar://83636964.
1 parent f4aa626 commit fc58596

File tree

4 files changed

+23
-8
lines changed

4 files changed

+23
-8
lines changed

lib/Sema/TypeCheckConcurrency.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -3720,7 +3720,7 @@ NormalProtocolConformance *GetImplicitSendableRequest::evaluate(
37203720
if (TypeChecker::conformsToKnownProtocol(
37213721
classDecl->mapTypeIntoContext(superclass),
37223722
KnownProtocolKind::Sendable,
3723-
classModule))
3723+
classModule, /*allowMissing=*/false))
37243724
return nullptr;
37253725
}
37263726
}

lib/Sema/TypeCheckProtocol.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -5182,9 +5182,10 @@ TypeChecker::containsProtocol(Type T, ProtocolDecl *Proto, ModuleDecl *M,
51825182
}
51835183

51845184
ProtocolConformanceRef
5185-
TypeChecker::conformsToProtocol(Type T, ProtocolDecl *Proto, ModuleDecl *M) {
5185+
TypeChecker::conformsToProtocol(Type T, ProtocolDecl *Proto, ModuleDecl *M,
5186+
bool allowMissing) {
51865187
// Look up conformance in the module.
5187-
auto lookupResult = M->lookupConformance(T, Proto, /*alllowMissing=*/true);
5188+
auto lookupResult = M->lookupConformance(T, Proto, allowMissing);
51885189
if (lookupResult.isInvalid()) {
51895190
return ProtocolConformanceRef::forInvalid();
51905191
}
@@ -5212,11 +5213,13 @@ TypeChecker::conformsToProtocol(Type T, ProtocolDecl *Proto, ModuleDecl *M) {
52125213
return lookupResult;
52135214
}
52145215

5215-
bool TypeChecker::conformsToKnownProtocol(Type type, KnownProtocolKind protocol,
5216-
ModuleDecl *module) {
5216+
bool TypeChecker::conformsToKnownProtocol(
5217+
Type type, KnownProtocolKind protocol, ModuleDecl *module,
5218+
bool allowMissing) {
52175219
if (auto *proto =
52185220
TypeChecker::getProtocol(module->getASTContext(), SourceLoc(), protocol))
5219-
return (bool)TypeChecker::conformsToProtocol(type, proto, module);
5221+
return (bool)TypeChecker::conformsToProtocol(
5222+
type, proto, module, allowMissing);
52205223
return false;
52215224
}
52225225

lib/Sema/TypeChecker.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -724,11 +724,12 @@ ProtocolConformanceRef containsProtocol(Type T, ProtocolDecl *Proto,
724724
/// \returns The protocol conformance, if \c T conforms to the
725725
/// protocol \c Proto, or \c None.
726726
ProtocolConformanceRef conformsToProtocol(Type T, ProtocolDecl *Proto,
727-
ModuleDecl *M);
727+
ModuleDecl *M,
728+
bool allowMissing = true);
728729

729730
/// Check whether the type conforms to a given known protocol.
730731
bool conformsToKnownProtocol(Type type, KnownProtocolKind protocol,
731-
ModuleDecl *module);
732+
ModuleDecl *module, bool allowMissing = true);
732733

733734
/// This is similar to \c conformsToProtocol, but returns \c true for cases where
734735
/// the type \p T could be dynamically cast to \p Proto protocol, such as a non-final

test/ClangImporter/objc_async.swift

+11
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,14 @@ func testMirrored(instance: ClassWithAsync) async {
170170
await instance.protocolMethod()
171171
await instance.customAsyncName()
172172
}
173+
174+
@MainActor class MyToolbarButton : NXButton {
175+
var count = 5
176+
177+
func f() {
178+
Task {
179+
let c = count
180+
print(c)
181+
}
182+
}
183+
}

0 commit comments

Comments
 (0)