Skip to content

Commit a723411

Browse files
author
Yui T
committed
Fix reporting duplication errors to report at all declarations
1 parent d049c29 commit a723411

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/compiler/binder.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,13 @@ module ts {
8484
if (node.name) {
8585
node.name.parent = node;
8686
}
87-
file.semanticErrors.push(createDiagnosticForNode(node.name ? node.name : node,
88-
Diagnostics.Duplicate_identifier_0, getDisplayName(node)));
87+
// Report errors every position with duplicate declarations
88+
// Report errors on previous encountered declarations
89+
forEach(symbol.declarations, (declaration) => {
90+
file.semanticErrors.push(createDiagnosticForNode(declaration.name, Diagnostics.Duplicate_identifier_0, getDisplayName(declaration)));
91+
});
92+
file.semanticErrors.push(createDiagnosticForNode(node, Diagnostics.Duplicate_identifier_0, getDisplayName(node)));
93+
8994
symbol = createSymbol(0, name);
9095
}
9196
}

src/compiler/checker.ts

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5668,6 +5668,8 @@ module ts {
56685668
// when checking exported function declarations across modules check only duplicate implementations
56695669
// names and consistency of modifiers are verified when we check local symbol
56705670
var isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & SymbolFlags.Module;
5671+
var duplicateFunctionDeclaration = false;
5672+
var multipleConstructorImplemenation = false;
56715673
for (var i = 0; i < declarations.length; i++) {
56725674
var node = <FunctionDeclaration>declarations[i];
56735675
var inAmbientContext = isInAmbientContext(node);
@@ -5690,10 +5692,10 @@ module ts {
56905692

56915693
if (node.body && bodyDeclaration) {
56925694
if (isConstructor) {
5693-
error(node, Diagnostics.Multiple_constructor_implementations_are_not_allowed);
5695+
multipleConstructorImplemenation = true;
56945696
}
56955697
else {
5696-
error(node, Diagnostics.Duplicate_function_implementation);
5698+
duplicateFunctionDeclaration = true;
56975699
}
56985700
}
56995701
else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) {
@@ -5717,6 +5719,18 @@ module ts {
57175719
}
57185720
}
57195721

5722+
if (multipleConstructorImplemenation) {
5723+
forEach(declarations, declaration => {
5724+
error(declaration, Diagnostics.Multiple_constructor_implementations_are_not_allowed);
5725+
});
5726+
}
5727+
5728+
if (duplicateFunctionDeclaration) {
5729+
forEach( declarations, declaration => {
5730+
error(declaration, Diagnostics.Duplicate_function_implementation);
5731+
});
5732+
}
5733+
57205734
if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body) {
57215735
reportImplementationExpectedError(lastSeenNonAmbientDeclaration);
57225736
}

0 commit comments

Comments
 (0)