Skip to content

Commit 0e00f51

Browse files
committed
Overload checking: implement simplistic overload checking for top-level
variables and types Swift SVN r15579
1 parent 286b309 commit 0e00f51

File tree

3 files changed

+3
-45
lines changed

3 files changed

+3
-45
lines changed

lib/Sema/NameBinding.cpp

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -256,35 +256,6 @@ void swift::performNameBinding(SourceFile &SF, unsigned StartElem) {
256256
// import statements after the first "chunk" should be rare, though.)
257257
// FIXME: Can we make this more efficient?
258258

259-
llvm::DenseMap<Identifier, ValueDecl*> CheckTypes;
260-
for (unsigned i = 0, e = SF.Decls.size(); i != e; ++i) {
261-
Decl *D = SF.Decls[i];
262-
if (D->isInvalid())
263-
// No need to diagnose redeclarations of invalid declarations, we have
264-
// already complained about them in some other way.
265-
continue;
266-
267-
if (ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
268-
// Check for declarations with the same name which aren't overloaded
269-
// vars/funcs.
270-
// FIXME: We don't have enough information to do this properly here,
271-
// because we need resolved types to find duplicates.
272-
if (!VD->hasName())
273-
continue;
274-
ValueDecl *&LookupD = CheckTypes[VD->getName()];
275-
ValueDecl *PrevD = LookupD;
276-
LookupD = VD;
277-
if (i >= StartElem) {
278-
if (PrevD && !((isa<VarDecl>(VD) || isa<FuncDecl>(VD)) &&
279-
(isa<VarDecl>(PrevD) || isa<FuncDecl>(PrevD)))) {
280-
Binder.diagnose(VD->getStartLoc(), diag::invalid_redecl);
281-
Binder.diagnose(PrevD, diag::invalid_redecl_prev,
282-
VD->getName());
283-
}
284-
}
285-
}
286-
}
287-
288259
SF.ASTStage = SourceFile::NameBound;
289260
verify(SF);
290261
}

lib/Sema/TypeChecker.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,9 @@ void swift::performTypeChecking(SourceFile &SF, TopLevelContext &TLC,
362362
auto &PrevOv = CheckOverloads[VD->getName()];
363363
if (i >= StartElem) {
364364
for (ValueDecl *PrevD : PrevOv) {
365-
if (PrevD->getType()->isEqual(VD->getType()) &&
366-
!haveDifferentFixity(PrevD, VD)) {
365+
if (isa<TypeDecl>(VD) || isa<VarDecl>(VD) ||
366+
(PrevD->getType()->isEqual(VD->getType()) &&
367+
!haveDifferentFixity(PrevD, VD))) {
367368
TC.diagnose(VD->getStartLoc(), diag::invalid_redecl);
368369
TC.diagnose(PrevD, diag::invalid_redecl_prev,
369370
VD->getName());

test/TypeCoercion/overload_assign.swift

Lines changed: 0 additions & 14 deletions
This file was deleted.

0 commit comments

Comments
 (0)