Skip to content

Commit 6b2fbb7

Browse files
committed
Sema: Fix crash in MissingConformanceFailure::diagnoseAsError()
It's difficult to trigger this because the code path is only reached for the standard operators. The issue in question was in embedded Swift due to an unsupported usage of the === operator, but we expect an upcoming standard library change to actually make us accept that code. However, the fix should be pretty safe, even without a test case. Fixes the crash in rdar://156095800.
1 parent 328dd1f commit 6b2fbb7

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -671,15 +671,17 @@ bool MissingConformanceFailure::diagnoseAsError() {
671671
};
672672

673673
// Limit this to `Equatable` and `Comparable` protocols for now.
674-
auto *protocol = getRHS()->castTo<ProtocolType>()->getDecl();
675-
if (isEnumWithAssociatedValues(getLHS()) &&
676-
(protocol->isSpecificProtocol(KnownProtocolKind::Equatable) ||
677-
protocol->isSpecificProtocol(KnownProtocolKind::Comparable))) {
678-
if (RequirementFailure::diagnoseAsError()) {
679-
auto opName = getOperatorName(expr);
680-
emitDiagnostic(diag::no_binary_op_overload_for_enum_with_payload,
681-
opName->str());
682-
return true;
674+
if (auto *protocolTy = getRHS()->getAs<ProtocolType>()) {
675+
auto *protocol = protocolTy->getDecl();
676+
if (isEnumWithAssociatedValues(getLHS()) &&
677+
(protocol->isSpecificProtocol(KnownProtocolKind::Equatable) ||
678+
protocol->isSpecificProtocol(KnownProtocolKind::Comparable))) {
679+
if (RequirementFailure::diagnoseAsError()) {
680+
auto opName = getOperatorName(expr);
681+
emitDiagnostic(diag::no_binary_op_overload_for_enum_with_payload,
682+
opName->str());
683+
return true;
684+
}
683685
}
684686
}
685687
}

0 commit comments

Comments
 (0)