Skip to content

Commit 38e305c

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
1 parent c345043 commit 38e305c

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
@@ -4703,6 +4703,8 @@ ValueDecl *TypeChecker::deriveProtocolRequirement(DeclContext *DC,
47034703
return nullptr;
47044704

47054705
auto Decl = DC->getInnermostDeclarationDeclContext();
4706+
if (Decl->isInvalid())
4707+
return nullptr;
47064708

47074709
switch (*knownKind) {
47084710
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)