mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
Overload checking: implement simplistic overload checking for top-level
variables and types Swift SVN r15579
This commit is contained in:
@@ -256,35 +256,6 @@ void swift::performNameBinding(SourceFile &SF, unsigned StartElem) {
|
||||
// import statements after the first "chunk" should be rare, though.)
|
||||
// FIXME: Can we make this more efficient?
|
||||
|
||||
llvm::DenseMap<Identifier, ValueDecl*> CheckTypes;
|
||||
for (unsigned i = 0, e = SF.Decls.size(); i != e; ++i) {
|
||||
Decl *D = SF.Decls[i];
|
||||
if (D->isInvalid())
|
||||
// No need to diagnose redeclarations of invalid declarations, we have
|
||||
// already complained about them in some other way.
|
||||
continue;
|
||||
|
||||
if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
|
||||
// Check for declarations with the same name which aren't overloaded
|
||||
// vars/funcs.
|
||||
// FIXME: We don't have enough information to do this properly here,
|
||||
// because we need resolved types to find duplicates.
|
||||
if (!VD->hasName())
|
||||
continue;
|
||||
ValueDecl *&LookupD = CheckTypes[VD->getName()];
|
||||
ValueDecl *PrevD = LookupD;
|
||||
LookupD = VD;
|
||||
if (i >= StartElem) {
|
||||
if (PrevD && !((isa<VarDecl>(VD) || isa<FuncDecl>(VD)) &&
|
||||
(isa<VarDecl>(PrevD) || isa<FuncDecl>(PrevD)))) {
|
||||
Binder.diagnose(VD->getStartLoc(), diag::invalid_redecl);
|
||||
Binder.diagnose(PrevD, diag::invalid_redecl_prev,
|
||||
VD->getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
SF.ASTStage = SourceFile::NameBound;
|
||||
verify(SF);
|
||||
}
|
||||
|
||||
@@ -362,8 +362,9 @@ void swift::performTypeChecking(SourceFile &SF, TopLevelContext &TLC,
|
||||
auto &PrevOv = CheckOverloads[VD->getName()];
|
||||
if (i >= StartElem) {
|
||||
for (ValueDecl *PrevD : PrevOv) {
|
||||
if (PrevD->getType()->isEqual(VD->getType()) &&
|
||||
!haveDifferentFixity(PrevD, VD)) {
|
||||
if (isa<TypeDecl>(VD) || isa<VarDecl>(VD) ||
|
||||
(PrevD->getType()->isEqual(VD->getType()) &&
|
||||
!haveDifferentFixity(PrevD, VD))) {
|
||||
TC.diagnose(VD->getStartLoc(), diag::invalid_redecl);
|
||||
TC.diagnose(PrevD, diag::invalid_redecl_prev,
|
||||
VD->getName());
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
// RUN: %swift -I %S/.. %s -verify
|
||||
|
||||
struct X { }
|
||||
struct Y { }
|
||||
|
||||
var a : X
|
||||
var a : Y
|
||||
|
||||
func test_assign(x : X, y : Y) {
|
||||
a = x
|
||||
a = y
|
||||
x = a
|
||||
y = a
|
||||
}
|
||||
Reference in New Issue
Block a user