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.
This commit is contained in:
Slava Pestov
2025-07-24 14:49:40 -04:00
parent 328dd1f753
commit 6b2fbb79b9

View File

@@ -671,15 +671,17 @@ bool MissingConformanceFailure::diagnoseAsError() {
};
// Limit this to `Equatable` and `Comparable` protocols for now.
auto *protocol = getRHS()->castTo<ProtocolType>()->getDecl();
if (isEnumWithAssociatedValues(getLHS()) &&
(protocol->isSpecificProtocol(KnownProtocolKind::Equatable) ||
protocol->isSpecificProtocol(KnownProtocolKind::Comparable))) {
if (RequirementFailure::diagnoseAsError()) {
auto opName = getOperatorName(expr);
emitDiagnostic(diag::no_binary_op_overload_for_enum_with_payload,
opName->str());
return true;
if (auto *protocolTy = getRHS()->getAs<ProtocolType>()) {
auto *protocol = protocolTy->getDecl();
if (isEnumWithAssociatedValues(getLHS()) &&
(protocol->isSpecificProtocol(KnownProtocolKind::Equatable) ||
protocol->isSpecificProtocol(KnownProtocolKind::Comparable))) {
if (RequirementFailure::diagnoseAsError()) {
auto opName = getOperatorName(expr);
emitDiagnostic(diag::no_binary_op_overload_for_enum_with_payload,
opName->str());
return true;
}
}
}
}