Skip to content

Commit dcbfa98

Browse files
authored
Merge pull request #69827 from xedin/fix-invalid-sendable-handling-in-existential-types
[Sema] Don't propagate `allowsMissing` to existential superclass check
2 parents 094e9ab + 862557d commit dcbfa98

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5777,12 +5777,16 @@ TypeChecker::containsProtocol(Type T, ProtocolDecl *Proto, ModuleDecl *M,
57775777

57785778
// First, if we have a superclass constraint, the class may conform
57795779
// concretely.
5780+
//
5781+
// Note that `allowMissing` is not propagated here because it
5782+
// would result in a missing conformance if type is `& Sendable`
5783+
// protocol composition. It's handled for type as a whole below.
57805784
if (auto superclass = layout.getSuperclass()) {
57815785
auto result =
57825786
(skipConditionalRequirements
5783-
? M->lookupConformance(superclass, Proto, allowMissing)
5784-
: TypeChecker::conformsToProtocol(
5785-
superclass, Proto, M, allowMissing));
5787+
? M->lookupConformance(superclass, Proto, /*allowMissing=*/false)
5788+
: TypeChecker::conformsToProtocol(superclass, Proto, M,
5789+
/*allowMissing=*/false));
57865790
if (result) {
57875791
return result;
57885792
}
@@ -5800,15 +5804,8 @@ TypeChecker::containsProtocol(Type T, ProtocolDecl *Proto, ModuleDecl *M,
58005804
return ProtocolConformanceRef(Proto);
58015805
}
58025806

5803-
// FIXME: Unify with shouldCreateMissingConformances
5804-
if (allowMissing &&
5805-
Proto->isSpecificProtocol(KnownProtocolKind::Sendable)) {
5806-
return ProtocolConformanceRef(
5807-
M->getASTContext().getBuiltinConformance(
5808-
T, Proto, BuiltinConformanceKind::Missing));
5809-
}
5810-
5811-
return ProtocolConformanceRef::forInvalid();
5807+
return allowMissing ? ProtocolConformanceRef::forMissingOrInvalid(T, Proto)
5808+
: ProtocolConformanceRef::forInvalid();
58125809
}
58135810

58145811
// For non-existential types, this is equivalent to checking conformance.

test/ClangImporter/objc_async.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -369,9 +369,7 @@ func testSender(
369369
sender.sendAnyArray([nonSendableObject])
370370
// expected-warning@-1 {{conformance of 'NonSendableClass' to 'Sendable' is unavailable; this is an error in Swift 6}}
371371

372-
sender.sendGeneric(sendableGeneric)
373-
// expected-warning@-1{{type 'GenericObject<SendableClass>' does not conform to the 'Sendable' protocol}}
374-
// FIXME: Shouldn't warn
372+
sender.sendGeneric(sendableGeneric) // no warning
375373

376374
sender.sendGeneric(nonSendableGeneric)
377375
// expected-warning@-1 {{type 'GenericObject<SendableClass>' does not conform to the 'Sendable' protocol}}

test/Concurrency/sendable_existentials.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,14 @@ func testESilently(a: Any, aOpt: Any?) {
5656
_ = sendable
5757
_ = arrayOfSendable
5858
}
59+
60+
func testErasure() {
61+
class A {}
62+
class B : A {}
63+
64+
func produce() -> any B & Sendable {
65+
fatalError()
66+
}
67+
68+
let _: any A & Sendable = produce() // no warning
69+
}

0 commit comments

Comments
 (0)