Skip to content

[Sema] Don't propagate allowsMissing to existential superclass check #69827

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5777,12 +5777,16 @@ TypeChecker::containsProtocol(Type T, ProtocolDecl *Proto, ModuleDecl *M,

// First, if we have a superclass constraint, the class may conform
// concretely.
//
// Note that `allowMissing` is not propagated here because it
// would result in a missing conformance if type is `& Sendable`
// protocol composition. It's handled for type as a whole below.
if (auto superclass = layout.getSuperclass()) {
auto result =
(skipConditionalRequirements
? M->lookupConformance(superclass, Proto, allowMissing)
: TypeChecker::conformsToProtocol(
superclass, Proto, M, allowMissing));
? M->lookupConformance(superclass, Proto, /*allowMissing=*/false)
: TypeChecker::conformsToProtocol(superclass, Proto, M,
/*allowMissing=*/false));
if (result) {
return result;
}
Expand All @@ -5800,15 +5804,8 @@ TypeChecker::containsProtocol(Type T, ProtocolDecl *Proto, ModuleDecl *M,
return ProtocolConformanceRef(Proto);
}

// FIXME: Unify with shouldCreateMissingConformances
if (allowMissing &&
Proto->isSpecificProtocol(KnownProtocolKind::Sendable)) {
return ProtocolConformanceRef(
M->getASTContext().getBuiltinConformance(
T, Proto, BuiltinConformanceKind::Missing));
}

return ProtocolConformanceRef::forInvalid();
return allowMissing ? ProtocolConformanceRef::forMissingOrInvalid(T, Proto)
: ProtocolConformanceRef::forInvalid();
}

// For non-existential types, this is equivalent to checking conformance.
Expand Down
4 changes: 1 addition & 3 deletions test/ClangImporter/objc_async.swift
Original file line number Diff line number Diff line change
Expand Up @@ -369,9 +369,7 @@ func testSender(
sender.sendAnyArray([nonSendableObject])
// expected-warning@-1 {{conformance of 'NonSendableClass' to 'Sendable' is unavailable; this is an error in Swift 6}}

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

sender.sendGeneric(nonSendableGeneric)
// expected-warning@-1 {{type 'GenericObject<SendableClass>' does not conform to the 'Sendable' protocol}}
Expand Down
11 changes: 11 additions & 0 deletions test/Concurrency/sendable_existentials.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,14 @@ func testESilently(a: Any, aOpt: Any?) {
_ = sendable
_ = arrayOfSendable
}

func testErasure() {
class A {}
class B : A {}

func produce() -> any B & Sendable {
fatalError()
}

let _: any A & Sendable = produce() // no warning
}