mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
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:
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user