Skip to content

Commit 3bd1a55

Browse files
committed
An @objc enum needs a valid raw type to make a special hash(into:)
This check is superfluous in correct code, but necessary in the 4.2 branch to avoid failing in incorrect code. (On master, the error is not reported because the enum is no longer considered @objc at this point.)
1 parent 3c01677 commit 3bd1a55

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

lib/Sema/DerivedConformanceEquatableHashable.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,12 +1233,18 @@ ValueDecl *DerivedConformance::deriveHashable(ValueDecl *requirement) {
12331233

12341234
if (auto ED = dyn_cast<EnumDecl>(Nominal)) {
12351235
void (*bodySynthesizer)(AbstractFunctionDecl *);
1236-
if (ED->isObjC())
1236+
if (ED->hasClangNode() ||
1237+
(ED->isObjC() && ED->hasRawType() &&
1238+
!ED->getInherited().front().isError())) {
1239+
// The checks for the raw type help avoid superfluous diagnostics in
1240+
// invalid code.
12371241
bodySynthesizer = deriveBodyHashable_enum_rawValue_hashInto;
1238-
else if (ED->hasOnlyCasesWithoutAssociatedValues())
1242+
} else if (ED->hasOnlyCasesWithoutAssociatedValues()) {
12391243
bodySynthesizer = deriveBodyHashable_enum_noAssociatedValues_hashInto;
1240-
else
1241-
bodySynthesizer=deriveBodyHashable_enum_hasAssociatedValues_hashInto;
1244+
} else {
1245+
bodySynthesizer =
1246+
deriveBodyHashable_enum_hasAssociatedValues_hashInto;
1247+
}
12421248
return deriveHashable_hashInto(*this, bodySynthesizer);
12431249
} else if (isa<StructDecl>(Nominal))
12441250
return deriveHashable_hashInto(*this,

0 commit comments

Comments
 (0)