Skip to content

Commit e9dd48b

Browse files
committed
Sema: Don't return fake abstract conformance from TypeChecker::containsProtocol()
1 parent b917e45 commit e9dd48b

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

lib/Sema/CSSimplify.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8465,7 +8465,7 @@ ConstraintSystem::SolutionKind ConstraintSystem::simplifyConformsToConstraint(
84658465
switch (kind) {
84668466
case ConstraintKind::Subtype: {
84678467
auto conformance = TypeChecker::containsProtocol(
8468-
type, protocol, /*allowMissing=*/true);
8468+
type, protocol, /*allowMissing=*/true).first;
84698469
if (conformance) {
84708470
return recordConformance(conformance);
84718471
}

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5320,7 +5320,7 @@ void swift::diagnoseConformanceFailure(Type T,
53205320
// If we're checking conformance of an existential type to a protocol,
53215321
// do a little bit of extra work to produce a better diagnostic.
53225322
if (T->isExistentialType() &&
5323-
TypeChecker::containsProtocol(T, Proto)) {
5323+
TypeChecker::containsProtocol(T, Proto).second) {
53245324

53255325
if (!T->isObjCExistentialType()) {
53265326
Type constraintType = T;
@@ -5453,7 +5453,7 @@ void swift::diagnoseConformanceFailure(Type T,
54535453
T, Proto->getDeclaredInterfaceType());
54545454
}
54555455

5456-
ProtocolConformanceRef
5456+
std::pair<ProtocolConformanceRef, bool>
54575457
TypeChecker::containsProtocol(Type T, ProtocolDecl *Proto,
54585458
bool allowMissing) {
54595459
// Existential types don't need to conform, i.e., they only need to
@@ -5467,7 +5467,8 @@ TypeChecker::containsProtocol(Type T, ProtocolDecl *Proto,
54675467
if (constraint->isEqual(Proto->getDeclaredInterfaceType()) &&
54685468
Proto->requiresSelfConformanceWitnessTable()) {
54695469
auto &ctx = T->getASTContext();
5470-
return ProtocolConformanceRef(ctx.getSelfConformance(Proto));
5470+
return std::make_pair(
5471+
ProtocolConformanceRef(ctx.getSelfConformance(Proto)), true);
54715472
}
54725473

54735474
auto layout = T->getExistentialLayout();
@@ -5482,7 +5483,7 @@ TypeChecker::containsProtocol(Type T, ProtocolDecl *Proto,
54825483
auto result =lookupConformance(superclass, Proto,
54835484
/*allowMissing=*/false);
54845485
if (result) {
5485-
return result;
5486+
return std::make_pair(result, true);
54865487
}
54875488
}
54885489

@@ -5491,19 +5492,21 @@ TypeChecker::containsProtocol(Type T, ProtocolDecl *Proto,
54915492
// If we found the protocol we're looking for, return an abstract
54925493
// conformance to it.
54935494
if (PD == Proto)
5494-
return ProtocolConformanceRef(Proto);
5495+
return std::make_pair(ProtocolConformanceRef(), true);
54955496

54965497
// Now check refined protocols.
54975498
if (PD->inheritsFrom(Proto))
5498-
return ProtocolConformanceRef(Proto);
5499+
return std::make_pair(ProtocolConformanceRef(), true);
54995500
}
55005501

5501-
return allowMissing ? ProtocolConformanceRef::forMissingOrInvalid(T, Proto)
5502-
: ProtocolConformanceRef::forInvalid();
5502+
auto conf = allowMissing ? ProtocolConformanceRef::forMissingOrInvalid(T, Proto)
5503+
: ProtocolConformanceRef::forInvalid();
5504+
return std::make_pair(conf, !!conf);
55035505
}
55045506

55055507
// For non-existential types, this is equivalent to checking conformance.
5506-
return lookupConformance(T, Proto, allowMissing);
5508+
auto conf = lookupConformance(T, Proto, allowMissing);
5509+
return std::make_pair(conf, !!conf);
55075510
}
55085511

55095512
bool TypeChecker::conformsToKnownProtocol(

lib/Sema/TypeChecker.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -808,8 +808,9 @@ Expr *addImplicitLoadExpr(
808808
///
809809
/// \returns the conformance, if \c T conforms to the protocol \c Proto, or
810810
/// an empty optional.
811-
ProtocolConformanceRef containsProtocol(Type T, ProtocolDecl *Proto,
812-
bool allowMissing=false);
811+
std::pair<ProtocolConformanceRef, bool>
812+
containsProtocol(Type T, ProtocolDecl *Proto,
813+
bool allowMissing=false);
813814

814815
/// Check whether the type conforms to a given known protocol.
815816
bool conformsToKnownProtocol(Type type, KnownProtocolKind protocol,

0 commit comments

Comments
 (0)