Skip to content

Commit 29e770b

Browse files
author
Yui
committed
Merge pull request #798 from Microsoft/flagAllDuplication
Flag all duplication
2 parents 1a3db28 + 5926a03 commit 29e770b

File tree

152 files changed

+1364
-346
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+1364
-346
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 declaration
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.name, 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
@@ -5696,6 +5696,8 @@ module ts {
56965696
// when checking exported function declarations across modules check only duplicate implementations
56975697
// names and consistency of modifiers are verified when we check local symbol
56985698
var isExportSymbolInsideModule = symbol.parent && symbol.parent.flags & SymbolFlags.Module;
5699+
var duplicateFunctionDeclaration = false;
5700+
var multipleConstructorImplementation = false;
56995701
for (var i = 0; i < declarations.length; i++) {
57005702
var node = <FunctionDeclaration>declarations[i];
57015703
var inAmbientContext = isInAmbientContext(node);
@@ -5718,10 +5720,10 @@ module ts {
57185720

57195721
if (node.body && bodyDeclaration) {
57205722
if (isConstructor) {
5721-
error(node, Diagnostics.Multiple_constructor_implementations_are_not_allowed);
5723+
multipleConstructorImplementation = true;
57225724
}
57235725
else {
5724-
error(node, Diagnostics.Duplicate_function_implementation);
5726+
duplicateFunctionDeclaration = true;
57255727
}
57265728
}
57275729
else if (!isExportSymbolInsideModule && previousDeclaration && previousDeclaration.parent === node.parent && previousDeclaration.end !== node.pos) {
@@ -5745,6 +5747,18 @@ module ts {
57455747
}
57465748
}
57475749

5750+
if (multipleConstructorImplementation) {
5751+
forEach(declarations, declaration => {
5752+
error(declaration, Diagnostics.Multiple_constructor_implementations_are_not_allowed);
5753+
});
5754+
}
5755+
5756+
if (duplicateFunctionDeclaration) {
5757+
forEach( declarations, declaration => {
5758+
error(declaration.name, Diagnostics.Duplicate_function_implementation);
5759+
});
5760+
}
5761+
57485762
if (!isExportSymbolInsideModule && lastSeenNonAmbientDeclaration && !lastSeenNonAmbientDeclaration.body) {
57495763
reportImplementationExpectedError(lastSeenNonAmbientDeclaration);
57505764
}

tests/baselines/reference/ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndGenericClassStaticFunctionOfTheSameName.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndGenericClassStaticFunctionOfTheSameName.ts(5,12): error TS2300: Duplicate identifier 'fn'.
12
tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndGenericClassStaticFunctionOfTheSameName.ts(10,21): error TS2300: Duplicate identifier 'fn'.
23

34

4-
==== tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndGenericClassStaticFunctionOfTheSameName.ts (1 errors) ====
5+
==== tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndGenericClassStaticFunctionOfTheSameName.ts (2 errors) ====
56
class clodule<T> {
67
id: string;
78
value: T;
89

910
static fn<U>(id: U) { }
11+
~~
12+
!!! error TS2300: Duplicate identifier 'fn'.
1013
}
1114

1215
module clodule {

tests/baselines/reference/ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndNonGenericClassStaticFunctionOfTheSameName.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
1+
tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndNonGenericClassStaticFunctionOfTheSameName.ts(5,12): error TS2300: Duplicate identifier 'fn'.
12
tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndNonGenericClassStaticFunctionOfTheSameName.ts(10,21): error TS2300: Duplicate identifier 'fn'.
23

34

4-
==== tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndNonGenericClassStaticFunctionOfTheSameName.ts (1 errors) ====
5+
==== tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithModulesExportedGenericFunctionAndNonGenericClassStaticFunctionOfTheSameName.ts (2 errors) ====
56
class clodule<T> {
67
id: string;
78
value: T;
89

910
static fn(id: string) { }
11+
~~
12+
!!! error TS2300: Duplicate identifier 'fn'.
1013
}
1114

1215
module clodule {

tests/baselines/reference/ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.errors.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.ts(4,12): error TS2300: Duplicate identifier 'Origin'.
12
tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.ts(8,21): error TS2300: Duplicate identifier 'Origin'.
3+
tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.ts(16,16): error TS2300: Duplicate identifier 'Origin'.
24
tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.ts(20,25): error TS2300: Duplicate identifier 'Origin'.
35

46

5-
==== tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.ts (2 errors) ====
7+
==== tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticFunctionAndExportedFunctionThatShareAName.ts (4 errors) ====
68
class Point {
79
constructor(public x: number, public y: number) { }
810

911
static Origin(): Point { return { x: 0, y: 0 }; } // unexpected error here bug 840246
12+
~~~~~~
13+
!!! error TS2300: Duplicate identifier 'Origin'.
1014
}
1115

1216
module Point {
@@ -21,6 +25,8 @@ tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMer
2125
constructor(public x: number, public y: number) { }
2226

2327
static Origin(): Point { return { x: 0, y: 0 }; } // unexpected error here bug 840246
28+
~~~~~~
29+
!!! error TS2300: Duplicate identifier 'Origin'.
2430
}
2531

2632
export module Point {

tests/baselines/reference/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.errors.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
1+
tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.ts(4,12): error TS2300: Duplicate identifier 'Origin'.
12
tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.ts(8,16): error TS2300: Duplicate identifier 'Origin'.
3+
tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.ts(16,16): error TS2300: Duplicate identifier 'Origin'.
24
tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.ts(20,20): error TS2300: Duplicate identifier 'Origin'.
35

46

5-
==== tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.ts (2 errors) ====
7+
==== tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithStaticVariableAndExportedVarThatShareAName.ts (4 errors) ====
68
class Point {
79
constructor(public x: number, public y: number) { }
810

911
static Origin: Point = { x: 0, y: 0 };
12+
~~~~~~
13+
!!! error TS2300: Duplicate identifier 'Origin'.
1014
}
1115

1216
module Point {
@@ -21,6 +25,8 @@ tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMer
2125
constructor(public x: number, public y: number) { }
2226

2327
static Origin: Point = { x: 0, y: 0 };
28+
~~~~~~
29+
!!! error TS2300: Duplicate identifier 'Origin'.
2430
}
2531

2632
export module Point {

tests/baselines/reference/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.errors.txt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1+
tests/cases/conformance/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.ts(2,18): error TS2300: Duplicate identifier 'Point'.
12
tests/cases/conformance/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.ts(10,18): error TS2300: Duplicate identifier 'Point'.
3+
tests/cases/conformance/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.ts(17,18): error TS2300: Duplicate identifier 'Line'.
24
tests/cases/conformance/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.ts(26,26): error TS2300: Duplicate identifier 'Line'.
35

46

5-
==== tests/cases/conformance/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.ts (2 errors) ====
7+
==== tests/cases/conformance/internalModules/DeclarationMerging/TwoInternalModulesThatMergeEachWithExportedClassesOfTheSameName.ts (4 errors) ====
68
module A {
79
export class Point {
10+
~~~~~
11+
!!! error TS2300: Duplicate identifier 'Point'.
812
x: number;
913
y: number;
1014
}
@@ -22,6 +26,8 @@ tests/cases/conformance/internalModules/DeclarationMerging/TwoInternalModulesTha
2226

2327
module X.Y.Z {
2428
export class Line {
29+
~~~~
30+
!!! error TS2300: Duplicate identifier 'Line'.
2531
length: number;
2632
}
2733
}

tests/baselines/reference/ambientClassOverloadForFunction.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
1+
tests/cases/compiler/ambientClassOverloadForFunction.ts(1,15): error TS2300: Duplicate identifier 'foo'.
12
tests/cases/compiler/ambientClassOverloadForFunction.ts(2,10): error TS2300: Duplicate identifier 'foo'.
23

34

4-
==== tests/cases/compiler/ambientClassOverloadForFunction.ts (1 errors) ====
5+
==== tests/cases/compiler/ambientClassOverloadForFunction.ts (2 errors) ====
56
declare class foo{};
7+
~~~
8+
!!! error TS2300: Duplicate identifier 'foo'.
69
function foo() { return null; }
710
~~~
811
!!! error TS2300: Duplicate identifier 'foo'.

tests/baselines/reference/anyDeclare.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
1+
tests/cases/compiler/anyDeclare.ts(3,9): error TS2300: Duplicate identifier 'myFn'.
12
tests/cases/compiler/anyDeclare.ts(4,14): error TS2300: Duplicate identifier 'myFn'.
23

34

4-
==== tests/cases/compiler/anyDeclare.ts (1 errors) ====
5+
==== tests/cases/compiler/anyDeclare.ts (2 errors) ====
56
declare var x: any;
67
module myMod {
78
var myFn;
9+
~~~~
10+
!!! error TS2300: Duplicate identifier 'myFn'.
811
function myFn() { }
912
~~~~
1013
!!! error TS2300: Duplicate identifier 'myFn'.
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,22 @@
1+
tests/cases/compiler/augmentedTypesClass.ts(2,7): error TS2300: Duplicate identifier 'c1'.
12
tests/cases/compiler/augmentedTypesClass.ts(3,5): error TS2300: Duplicate identifier 'c1'.
3+
tests/cases/compiler/augmentedTypesClass.ts(6,7): error TS2300: Duplicate identifier 'c4'.
24
tests/cases/compiler/augmentedTypesClass.ts(7,6): error TS2300: Duplicate identifier 'c4'.
35

46

5-
==== tests/cases/compiler/augmentedTypesClass.ts (2 errors) ====
7+
==== tests/cases/compiler/augmentedTypesClass.ts (4 errors) ====
68
//// class then var
79
class c1 { public foo() { } }
10+
~~
11+
!!! error TS2300: Duplicate identifier 'c1'.
812
var c1 = 1; // error
913
~~
1014
!!! error TS2300: Duplicate identifier 'c1'.
1115

1216
//// class then enum
1317
class c4 { public foo() { } }
18+
~~
19+
!!! error TS2300: Duplicate identifier 'c4'.
1420
enum c4 { One } // error
1521
~~
1622
!!! error TS2300: Duplicate identifier 'c4'.

0 commit comments

Comments
 (0)