Skip to content

Commit 2559ce1

Browse files
committed
Sema: TypeChecker::conformsToProtocol() should only compute conditional requirements if checking them
This fixes a crash with the next commit.
1 parent 8518fc2 commit 2559ce1

File tree

4 files changed

+12
-18
lines changed

4 files changed

+12
-18
lines changed

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,9 @@ LookupTypeResult TypeChecker::lookupMemberType(DeclContext *dc,
555555
auto typeDecl =
556556
concrete->getTypeWitnessAndDecl(assocType, lazyResolver).second;
557557

558-
assert(typeDecl && "Missing type witness?");
558+
// Circularity.
559+
if (!typeDecl)
560+
continue;
559561

560562
auto memberType =
561563
substMemberTypeWithBase(dc->getParentModule(), typeDecl, type);

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4113,18 +4113,17 @@ Optional<ProtocolConformanceRef> TypeChecker::conformsToProtocol(
41134113
recordDependency();
41144114
}
41154115

4116+
if (options.contains(ConformanceCheckFlags::SkipConditionalRequirements))
4117+
return lookupResult;
4118+
41164119
auto condReqs = lookupResult->getConditionalRequirementsIfAvailable();
4120+
assert(condReqs &&
4121+
"unhandled recursion: missing conditional requirements when they're "
4122+
"required");
4123+
41174124
// If we have a conditional requirements that
41184125
// we need to check, do so now.
4119-
if (!condReqs) {
4120-
assert(
4121-
options.contains(
4122-
ConformanceCheckFlags::AllowUnavailableConditionalRequirements) &&
4123-
"unhandled recursion: missing conditional requirements when they're "
4124-
"required");
4125-
} else if (!condReqs->empty() &&
4126-
!options.contains(
4127-
ConformanceCheckFlags::SkipConditionalRequirements)) {
4126+
if (!condReqs->empty()) {
41284127
// Figure out the location of the conditional conformance.
41294128
auto conformanceDC = lookupResult->getConcrete()->getDeclContext();
41304129
SourceLoc noteLoc;

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -937,7 +937,7 @@ static void maybeDiagnoseBadConformanceRef(DeclContext *dc,
937937
parentTy, protocol, dc,
938938
(ConformanceCheckFlags::InExpression |
939939
ConformanceCheckFlags::SuppressDependencyTracking |
940-
ConformanceCheckFlags::AllowUnavailableConditionalRequirements))) {
940+
ConformanceCheckFlags::SkipConditionalRequirements))) {
941941
if (conformanceRef->isConcrete())
942942
conformance = conformanceRef->getConcrete();
943943
}

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -502,13 +502,6 @@ enum class ConformanceCheckFlags {
502502
/// correctly used. Otherwise (the default), all of the conditional
503503
/// requirements will be checked.
504504
SkipConditionalRequirements = 0x04,
505-
506-
/// Whether to require that the conditional requirements have been computed.
507-
///
508-
/// When set, if the conditional requirements aren't available, they are just
509-
/// skipped, and the caller is responsible for detecting and handling this
510-
/// case (likely via another call to getConditionalRequirementsIfAvailable).
511-
AllowUnavailableConditionalRequirements = 0x08,
512505
};
513506

514507
/// Options that control protocol conformance checking.

0 commit comments

Comments
 (0)