Skip to content

Commit d0f9b7c

Browse files
Suyash SrijanSuyash Srijan
authored andcommitted
[typechecker] check for nominal types as well when comparing enum elements
1 parent 91b41fc commit d0f9b7c

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,9 @@ struct OverloadSignature {
216216
/// Whether this is a enum element.
217217
unsigned IsEnumElement : 1;
218218

219+
/// Whether this is a nominal type.
220+
unsigned IsNominal : 1;
221+
219222
/// Whether this signature is part of a protocol extension.
220223
unsigned InProtocolExtension : 1;
221224

lib/AST/Decl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2098,6 +2098,12 @@ bool swift::conflicting(ASTContext &ctx,
20982098
return false;
20992099
}
21002100

2101+
// Nominal types and enum elements always conflict with each other.
2102+
if ((sig1.IsNominal && sig2.IsEnumElement) ||
2103+
(sig1.IsEnumElement && sig2.IsNominal)) {
2104+
return true;
2105+
}
2106+
21012107
// Enum elements always conflict with each other. At this point, they
21022108
// have the same base name but different types.
21032109
if (sig1.IsEnumElement && sig2.IsEnumElement) {
@@ -2263,6 +2269,7 @@ OverloadSignature ValueDecl::getOverloadSignature() const {
22632269
signature.IsVariable = isa<VarDecl>(this);
22642270
signature.IsFunction = isa<AbstractFunctionDecl>(this);
22652271
signature.IsEnumElement = isa<EnumElementDecl>(this);
2272+
signature.IsNominal = isa<NominalTypeDecl>(this);
22662273

22672274
// Unary operators also include prefix/postfix.
22682275
if (auto func = dyn_cast<FuncDecl>(this)) {

0 commit comments

Comments
 (0)