Skip to content

Commit 025555f

Browse files
committed
Sema: Remove duplicate enum case check
This is already handled by the common redeclaration check.
1 parent 4be9a60 commit 025555f

File tree

3 files changed

+17
-43
lines changed

3 files changed

+17
-43
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,10 +2163,6 @@ ERROR(self_in_nominal,none,
21632163
"'Self' is only available in a protocol or as the result of a "
21642164
"method in a class; did you mean '%0'?", (StringRef))
21652165

2166-
// Duplicate declarations
2167-
ERROR(duplicate_enum_element,none,
2168-
"duplicate definition of enum element",())
2169-
21702166
// Property behaviors
21712167
ERROR(property_behavior_not_protocol,none,
21722168
"property behavior name must refer to a protocol", ())

lib/Sema/TypeCheckDecl.cpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4366,28 +4366,6 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
43664366
checkCircularity(TC, ED, diag::circular_enum_inheritance,
43674367
diag::enum_here, path);
43684368
}
4369-
{
4370-
// Check for duplicate enum members.
4371-
llvm::DenseMap<Identifier, EnumElementDecl *> Elements;
4372-
bool hasErrors = false;
4373-
for (auto *EED : ED->getAllElements()) {
4374-
auto Res = Elements.insert({ EED->getName(), EED });
4375-
if (!Res.second) {
4376-
EED->setInvalid();
4377-
4378-
auto PreviousEED = Res.first->second;
4379-
TC.diagnose(EED->getLoc(), diag::duplicate_enum_element);
4380-
TC.diagnose(PreviousEED->getLoc(),
4381-
diag::previous_decldef, true, EED->getName());
4382-
hasErrors = true;
4383-
}
4384-
}
4385-
4386-
// If one of the cases is invalid, let's mark
4387-
// whole enum as invalid as well.
4388-
if (hasErrors)
4389-
ED->setInvalid();
4390-
}
43914369
}
43924370

43934371
if (!IsFirstPass) {
@@ -4401,7 +4379,7 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
44014379

44024380
TC.checkConformancesInContext(ED, ED);
44034381
}
4404-
4382+
44054383
for (Decl *member : ED->getMembers())
44064384
visit(member);
44074385

test/Parse/enum.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -324,40 +324,40 @@ enum RawTypeMismatch : Int { // expected-error {{'RawTypeMismatch' declares raw
324324
}
325325

326326
enum DuplicateMembers1 {
327-
case Foo // expected-note {{previous definition of 'Foo' is here}}
328-
case Foo // expected-error {{duplicate definition of enum element}}
327+
case Foo // expected-note {{'Foo' previously declared here}}
328+
case Foo // expected-error {{invalid redeclaration of 'Foo'}}
329329
}
330330

331331
enum DuplicateMembers2 {
332-
case Foo, Bar // expected-note {{previous definition of 'Foo' is here}} expected-note {{previous definition of 'Bar' is here}}
333-
case Foo // expected-error {{duplicate definition of enum element}}
334-
case Bar // expected-error {{duplicate definition of enum element}}
332+
case Foo, Bar // expected-note {{'Foo' previously declared here}} expected-note {{'Bar' previously declared here}}
333+
case Foo // expected-error {{invalid redeclaration of 'Foo'}}
334+
case Bar // expected-error {{invalid redeclaration of 'Bar'}}
335335
}
336336

337337
enum DuplicateMembers3 {
338-
case Foo // expected-note {{previous definition of 'Foo' is here}}
339-
case Foo(Int) // expected-error {{duplicate definition of enum element}}
338+
case Foo // expected-note {{'Foo' previously declared here}}
339+
case Foo(Int) // expected-error {{invalid redeclaration of 'Foo'}}
340340
}
341341

342342
enum DuplicateMembers4 : Int { // expected-error {{'DuplicateMembers4' declares raw type 'Int', but does not conform to RawRepresentable and conformance could not be synthesized}}
343-
case Foo = 1 // expected-note {{previous definition of 'Foo' is here}}
344-
case Foo = 2 // expected-error {{duplicate definition of enum element}}
343+
case Foo = 1 // expected-note {{'Foo' previously declared here}}
344+
case Foo = 2 // expected-error {{invalid redeclaration of 'Foo'}}
345345
}
346346

347347
enum DuplicateMembers5 : Int { // expected-error {{'DuplicateMembers5' declares raw type 'Int', but does not conform to RawRepresentable and conformance could not be synthesized}}
348-
case Foo = 1 // expected-note {{previous definition of 'Foo' is here}}
349-
case Foo = 1 + 1 // expected-error {{duplicate definition of enum element}} expected-error {{raw value for enum case must be a literal}}
348+
case Foo = 1 // expected-note {{'Foo' previously declared here}}
349+
case Foo = 1 + 1 // expected-error {{invalid redeclaration of 'Foo'}} expected-error {{raw value for enum case must be a literal}}
350350
}
351351

352352
enum DuplicateMembers6 {
353-
case Foo // expected-note 2{{previous definition of 'Foo' is here}}
354-
case Foo // expected-error {{duplicate definition of enum element}}
355-
case Foo // expected-error {{duplicate definition of enum element}}
353+
case Foo // expected-note 2{{'Foo' previously declared here}}
354+
case Foo // expected-error {{invalid redeclaration of 'Foo'}}
355+
case Foo // expected-error {{invalid redeclaration of 'Foo'}}
356356
}
357357

358358
enum DuplicateMembers7 : String { // expected-error {{'DuplicateMembers7' declares raw type 'String', but does not conform to RawRepresentable and conformance could not be synthesized}}
359-
case Foo // expected-note {{previous definition of 'Foo' is here}}
360-
case Foo = "Bar" // expected-error {{duplicate definition of enum element}}
359+
case Foo // expected-note {{'Foo' previously declared here}}
360+
case Foo = "Bar" // expected-error {{invalid redeclaration of 'Foo'}}
361361
}
362362

363363
// Refs to duplicated enum cases shouldn't crash the compiler.

0 commit comments

Comments
 (0)