Skip to content

Commit 4270f3f

Browse files
Suyash SrijanSuyash Srijan
authored andcommitted
[typechecker] check for typealias as well
1 parent 3fb56bc commit 4270f3f

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ struct OverloadSignature {
219219
/// Whether this is a nominal type.
220220
unsigned IsNominal : 1;
221221

222+
/// Whether this is a type alias.
223+
unsigned IsTypeAlias : 1;
224+
222225
/// Whether this signature is part of a protocol extension.
223226
unsigned InProtocolExtension : 1;
224227

lib/AST/Decl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2104,6 +2104,12 @@ bool swift::conflicting(ASTContext &ctx,
21042104
return true;
21052105
}
21062106

2107+
// Typealiases and enum elements always conflict with each other.
2108+
if ((sig1.IsTypeAlias && sig2.IsEnumElement) ||
2109+
(sig1.IsEnumElement && sig2.IsTypeAlias)) {
2110+
return true;
2111+
}
2112+
21072113
// Enum elements always conflict with each other. At this point, they
21082114
// have the same base name but different types.
21092115
if (sig1.IsEnumElement && sig2.IsEnumElement) {
@@ -2270,6 +2276,7 @@ OverloadSignature ValueDecl::getOverloadSignature() const {
22702276
signature.IsFunction = isa<AbstractFunctionDecl>(this);
22712277
signature.IsEnumElement = isa<EnumElementDecl>(this);
22722278
signature.IsNominal = isa<NominalTypeDecl>(this);
2279+
signature.IsTypeAlias = isa<TypeAliasDecl>(this);
22732280

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

test/decl/overload.swift

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,30 @@ enum SR_10084_E_10 {
568568

569569
enum SR_10084_E_11 {
570570
case A // expected-note {{found this candidate}} // expected-note {{'A' previously declared here}}
571-
static let A: SR_10084_E_11 = .A // expected-note {{found this candidate}} // expected-error {{invalid redeclaration of 'A'}} // expected-error {{ambiguous use of 'A'}}
571+
static var A: SR_10084_E_11 = .A // expected-note {{found this candidate}} // expected-error {{invalid redeclaration of 'A'}} // expected-error {{ambiguous use of 'A'}}
572572
}
573573

574574
enum SR_10084_E_12 {
575-
static let A: SR_10084_E_12 = .A // expected-note {{found this candidate}} // expected-note {{'A' previously declared here}} // expected-error {{ambiguous use of 'A'}}
575+
static var A: SR_10084_E_12 = .A // expected-note {{found this candidate}} // expected-note {{'A' previously declared here}} // expected-error {{ambiguous use of 'A'}}
576576
case A // expected-note {{found this candidate}} // expected-error {{invalid redeclaration of 'A'}}
577577
}
578+
579+
enum SR_10084_E_13 {
580+
case X // expected-note {{'X' previously declared here}}
581+
struct X<T> {} // expected-error {{invalid redeclaration of 'X'}}
582+
}
583+
584+
enum SR_10084_E_14 {
585+
struct X<T> {} // expected-note {{'X' previously declared here}}
586+
case X // expected-error {{invalid redeclaration of 'X'}}
587+
}
588+
589+
enum SR_10084_E_15 {
590+
case Y // expected-note {{'Y' previously declared here}}
591+
typealias Y = Int // expected-error {{invalid redeclaration of 'Y'}}
592+
}
593+
594+
enum SR_10084_E_16 {
595+
typealias Z = Int // expected-note {{'Z' previously declared here}}
596+
case Z // expected-error {{invalid redeclaration of 'Z'}}
597+
}

0 commit comments

Comments
 (0)