Skip to content

Commit d1d0763

Browse files
authored
Merge pull request swiftlang#14423 from xedin/rdar-36989792-5.0
[5.0] [DeclChecker] Don't try to derive conformances for invalid enums
2 parents 43c56b3 + e326138 commit d1d0763

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
@@ -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)