Skip to content

Commit 3301b5a

Browse files
committed
[DeclChecker] Avoid setting ErrorType on the enum cases with duplicate names
We want to preserve as much of the AST as possible in the valid state, so for cases with duplicate names it makes sense to mark declaration itself and its parent enum as invalid and leave the original types in place.
1 parent 38e305c commit 3301b5a

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

lib/Sema/TypeCheckDecl.cpp

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4522,10 +4522,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
45224522
for (auto *EED : ED->getAllElements()) {
45234523
auto Res = Elements.insert({ EED->getName(), EED });
45244524
if (!Res.second) {
4525-
EED->setInterfaceType(ErrorType::get(TC.Context));
45264525
EED->setInvalid();
4527-
if (auto *RawValueExpr = EED->getRawValueExpr())
4528-
RawValueExpr->setType(ErrorType::get(TC.Context));
45294526

45304527
auto PreviousEED = Res.first->second;
45314528
TC.diagnose(EED->getLoc(), diag::duplicate_enum_element);
@@ -4535,10 +4532,10 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
45354532
}
45364533
}
45374534

4538-
if (hasErrors) {
4539-
ED->setInterfaceType(ErrorType::get(TC.Context));
4535+
// If one of the cases is invalid, let's mark
4536+
// whole enum as invalid as well.
4537+
if (hasErrors)
45404538
ED->setInvalid();
4541-
}
45424539
}
45434540
}
45444541

0 commit comments

Comments
 (0)