Skip to content

Commit 1a02213

Browse files
authored
Merge pull request #14419 from xedin/rdar-36989792
[DeclChecker] Don't try to derive conformances for invalid enums
2 parents f69d756 + 3301b5a commit 1a02213

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4518,20 +4518,24 @@ 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) {
4524-
EED->setInterfaceType(ErrorType::get(TC.Context));
45254525
EED->setInvalid();
4526-
if (auto *RawValueExpr = EED->getRawValueExpr())
4527-
RawValueExpr->setType(ErrorType::get(TC.Context));
45284526

45294527
auto PreviousEED = Res.first->second;
45304528
TC.diagnose(EED->getLoc(), diag::duplicate_enum_element);
45314529
TC.diagnose(PreviousEED->getLoc(),
45324530
diag::previous_decldef, true, EED->getName());
4531+
hasErrors = true;
45334532
}
45344533
}
4534+
4535+
// If one of the cases is invalid, let's mark
4536+
// whole enum as invalid as well.
4537+
if (hasErrors)
4538+
ED->setInvalid();
45354539
}
45364540
}
45374541

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)