Skip to content

Commit 425de49

Browse files
committed
[Sema] Synthesize Eq/Hash for enums with payloads, structs
1 parent 4777f9d commit 425de49

File tree

2 files changed

+767
-78
lines changed

2 files changed

+767
-78
lines changed

lib/AST/Decl.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2165,8 +2165,14 @@ bool NominalTypeDecl::derivesProtocolConformance(ProtocolDecl *protocol) const {
21652165
// Hashable conformance.
21662166
case KnownProtocolKind::Equatable:
21672167
case KnownProtocolKind::Hashable:
2168-
return enumDecl->hasCases()
2169-
&& enumDecl->hasOnlyCasesWithoutAssociatedValues();
2168+
// FIXME: This is too lenient; we can only promise to provide a witness
2169+
// for enums where all associated values conform to the protocol.
2170+
// Unfortunately, figuring this out requires a TypeChecker and resolving
2171+
// the argument type of each enum element. Instead, we let
2172+
// DerivedConformance::derive{Equatable,Hashable} perform the full check
2173+
// and it outputs its own diagnostics if conformance cannot be
2174+
// synthesized.
2175+
return enumDecl->hasCases();
21702176

21712177
// @objc enums can explicitly derive their _BridgedNSError conformance.
21722178
case KnownProtocolKind::BridgedNSError:

0 commit comments

Comments
 (0)