Skip to content

Commit 0d0867c

Browse files
committed
[DeclChecker] Don't try to derive conformances for invalid enums
If one of the cases is invalid, let's mark parent enum as invalid as well, and avoid trying to derive any conformances related to it. Resolves: rdar://problem/36989792 (cherry picked from commit 38e305c)
1 parent 1a168a6 commit 0d0867c

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4518,6 +4518,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
45184518
{
45194519
// Check for duplicate enum members.
45204520
llvm::DenseMap<Identifier, EnumElementDecl *> Elements;
4521+
bool hasErrors = false;
45214522
for (auto *EED : ED->getAllElements()) {
45224523
auto Res = Elements.insert({ EED->getName(), EED });
45234524
if (!Res.second) {
@@ -4530,8 +4531,14 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
45304531
TC.diagnose(EED->getLoc(), diag::duplicate_enum_element);
45314532
TC.diagnose(PreviousEED->getLoc(),
45324533
diag::previous_decldef, true, EED->getName());
4534+
hasErrors = true;
45334535
}
45344536
}
4537+
4538+
if (hasErrors) {
4539+
ED->setInterfaceType(ErrorType::get(TC.Context));
4540+
ED->setInvalid();
4541+
}
45354542
}
45364543
}
45374544

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4655,6 +4655,8 @@ ValueDecl *TypeChecker::deriveProtocolRequirement(DeclContext *DC,
46554655
return nullptr;
46564656

46574657
auto Decl = DC->getInnermostDeclarationDeclContext();
4658+
if (Decl->isInvalid())
4659+
return nullptr;
46584660

46594661
switch (*knownKind) {
46604662
case KnownProtocolKind::RawRepresentable:
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// RUN: not %target-swift-frontend %s -typecheck
2+
3+
enum E : Equatable {
4+
case c(Int)
5+
case c(String)
6+
}

0 commit comments

Comments
 (0)