Skip to content

Commit cffc62a

Browse files
committed
Report duplicate identifier errors on all locations for merged declarations to align with local declarations
1 parent 318575c commit cffc62a

21 files changed

+161
-129
lines changed

src/compiler/checker.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,9 @@ module ts {
226226
forEach(source.declarations, node => {
227227
error(node.name ? node.name : node, Diagnostics.Duplicate_identifier_0, symbolToString(source));
228228
});
229+
forEach(target.declarations, node => {
230+
error(node.name ? node.name : node, Diagnostics.Duplicate_identifier_0, symbolToString(source));
231+
});
229232
}
230233
}
231234

tests/baselines/reference/functionTypeArgumentArrayAssignment.errors.txt

Lines changed: 0 additions & 15 deletions
This file was deleted.
Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
//// [functionTypeArgumentArrayAssignment.ts]
2-
interface Array<T> {
3-
foo: T;
4-
length: number;
5-
}
2+
module test {
3+
interface Array<T> {
4+
foo: T;
5+
length: number;
6+
}
67

7-
function map<U>() {
8-
var ys: U[] = [];
8+
function map<U>() {
9+
var ys: U[] = [];
10+
}
911
}
1012

1113

1214
//// [functionTypeArgumentArrayAssignment.js]
13-
function map() {
14-
var ys = [];
15-
}
15+
var test;
16+
(function (test) {
17+
function map() {
18+
var ys = [];
19+
}
20+
})(test || (test = {}));
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
=== tests/cases/compiler/functionTypeArgumentArrayAssignment.ts ===
2+
module test {
3+
>test : typeof test
4+
5+
interface Array<T> {
6+
>Array : Array<T>
7+
>T : T
8+
9+
foo: T;
10+
>foo : T
11+
>T : T
12+
13+
length: number;
14+
>length : number
15+
}
16+
17+
function map<U>() {
18+
>map : <U>() => void
19+
>U : U
20+
21+
var ys: U[] = [];
22+
>ys : U[]
23+
>U : U
24+
>[] : U[]
25+
}
26+
}
27+
Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
1-
tests/cases/compiler/instanceofOperator.ts(6,7): error TS2300: Duplicate identifier 'Object'.
2-
tests/cases/compiler/instanceofOperator.ts(11,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
3-
tests/cases/compiler/instanceofOperator.ts(14,16): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.
4-
tests/cases/compiler/instanceofOperator.ts(15,19): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.
5-
tests/cases/compiler/instanceofOperator.ts(18,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
6-
tests/cases/compiler/instanceofOperator.ts(20,1): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
1+
tests/cases/compiler/instanceofOperator.ts(12,5): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
2+
tests/cases/compiler/instanceofOperator.ts(15,20): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.
3+
tests/cases/compiler/instanceofOperator.ts(16,23): error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.
4+
tests/cases/compiler/instanceofOperator.ts(19,5): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
5+
tests/cases/compiler/instanceofOperator.ts(21,5): error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
76

87

9-
==== tests/cases/compiler/instanceofOperator.ts (6 errors) ====
8+
==== tests/cases/compiler/instanceofOperator.ts (5 errors) ====
109
// Spec:
1110
// The instanceof operator requires the left operand to be of type Any or an object type, and the right
1211
// operand to be of type Any or a subtype of the ‘Function’ interface type. The result is always of the
1312
// Boolean primitive type.
1413

15-
class Object { }
16-
~~~~~~
17-
!!! error TS2300: Duplicate identifier 'Object'.
18-
var obj: Object;
14+
module test {
15+
class Object { }
16+
var obj: Object;
1917

2018

2119

22-
4 instanceof null;
23-
~
20+
4 instanceof null;
21+
~
2422
!!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
2523

26-
// Error and should be error
27-
obj instanceof 4;
28-
~
24+
// Error and should be error
25+
obj instanceof 4;
26+
~
2927
!!! error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.
30-
Object instanceof obj;
31-
~~~
28+
Object instanceof obj;
29+
~~~
3230
!!! error TS2359: The right-hand side of an 'instanceof' expression must be of type 'any' or of a type assignable to the 'Function' interface type.
3331

34-
// Error on left hand side
35-
null instanceof null;
36-
~~~~
32+
// Error on left hand side
33+
null instanceof null;
34+
~~~~
3735
!!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
38-
obj instanceof Object;
39-
undefined instanceof undefined;
40-
~~~~~~~~~
36+
obj instanceof Object;
37+
undefined instanceof undefined;
38+
~~~~~~~~~
4139
!!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
40+
}
4241

4342

tests/baselines/reference/instanceofOperator.js

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,23 @@
44
// operand to be of type Any or a subtype of the ‘Function’ interface type. The result is always of the
55
// Boolean primitive type.
66

7-
class Object { }
8-
var obj: Object;
7+
module test {
8+
class Object { }
9+
var obj: Object;
910

1011

1112

12-
4 instanceof null;
13+
4 instanceof null;
1314

14-
// Error and should be error
15-
obj instanceof 4;
16-
Object instanceof obj;
15+
// Error and should be error
16+
obj instanceof 4;
17+
Object instanceof obj;
1718

18-
// Error on left hand side
19-
null instanceof null;
20-
obj instanceof Object;
21-
undefined instanceof undefined;
19+
// Error on left hand side
20+
null instanceof null;
21+
obj instanceof Object;
22+
undefined instanceof undefined;
23+
}
2224

2325

2426

@@ -27,17 +29,20 @@ undefined instanceof undefined;
2729
// The instanceof operator requires the left operand to be of type Any or an object type, and the right
2830
// operand to be of type Any or a subtype of the ‘Function’ interface type. The result is always of the
2931
// Boolean primitive type.
30-
var Object = (function () {
31-
function Object() {
32-
}
33-
return Object;
34-
})();
35-
var obj;
36-
4 instanceof null;
37-
// Error and should be error
38-
obj instanceof 4;
39-
Object instanceof obj;
40-
// Error on left hand side
41-
null instanceof null;
42-
obj instanceof Object;
43-
undefined instanceof undefined;
32+
var test;
33+
(function (test) {
34+
var Object = (function () {
35+
function Object() {
36+
}
37+
return Object;
38+
})();
39+
var obj;
40+
4 instanceof null;
41+
// Error and should be error
42+
obj instanceof 4;
43+
Object instanceof obj;
44+
// Error on left hand side
45+
null instanceof null;
46+
obj instanceof Object;
47+
undefined instanceof undefined;
48+
})(test || (test = {}));

tests/baselines/reference/letDeclarations-scopes-duplicates2.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
tests/cases/compiler/file1.ts(2,5): error TS2300: Duplicate identifier 'var1'.
12
tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'.
23

34

4-
==== tests/cases/compiler/file1.ts (0 errors) ====
5+
==== tests/cases/compiler/file1.ts (1 errors) ====
56

67
let var1 = 0;
8+
~~~~
9+
!!! error TS2300: Duplicate identifier 'var1'.
710

811
==== tests/cases/compiler/file2.ts (1 errors) ====
912
let var1 = 0;

tests/baselines/reference/letDeclarations-scopes-duplicates3.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
tests/cases/compiler/file1.ts(2,5): error TS2300: Duplicate identifier 'var1'.
12
tests/cases/compiler/file2.ts(1,7): error TS2300: Duplicate identifier 'var1'.
23

34

4-
==== tests/cases/compiler/file1.ts (0 errors) ====
5+
==== tests/cases/compiler/file1.ts (1 errors) ====
56

67
let var1 = 0;
8+
~~~~
9+
!!! error TS2300: Duplicate identifier 'var1'.
710

811
==== tests/cases/compiler/file2.ts (1 errors) ====
912
const var1 = 0;

tests/baselines/reference/letDeclarations-scopes-duplicates4.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
tests/cases/compiler/file1.ts(2,7): error TS2300: Duplicate identifier 'var1'.
12
tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'.
23

34

4-
==== tests/cases/compiler/file1.ts (0 errors) ====
5+
==== tests/cases/compiler/file1.ts (1 errors) ====
56

67
const var1 = 0;
8+
~~~~
9+
!!! error TS2300: Duplicate identifier 'var1'.
710

811
==== tests/cases/compiler/file2.ts (1 errors) ====
912
let var1 = 0;

tests/baselines/reference/letDeclarations-scopes-duplicates5.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
tests/cases/compiler/file1.ts(2,7): error TS2300: Duplicate identifier 'var1'.
12
tests/cases/compiler/file2.ts(1,7): error TS2300: Duplicate identifier 'var1'.
23

34

4-
==== tests/cases/compiler/file1.ts (0 errors) ====
5+
==== tests/cases/compiler/file1.ts (1 errors) ====
56

67
const var1 = 0;
8+
~~~~
9+
!!! error TS2300: Duplicate identifier 'var1'.
710

811
==== tests/cases/compiler/file2.ts (1 errors) ====
912
const var1 = 0;

tests/baselines/reference/letDeclarations-scopes-duplicates6.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
tests/cases/compiler/file1.ts(2,5): error TS2300: Duplicate identifier 'var1'.
12
tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'.
23

34

4-
==== tests/cases/compiler/file1.ts (0 errors) ====
5+
==== tests/cases/compiler/file1.ts (1 errors) ====
56

67
var var1 = 0;
8+
~~~~
9+
!!! error TS2300: Duplicate identifier 'var1'.
710

811
==== tests/cases/compiler/file2.ts (1 errors) ====
912
let var1 = 0;

tests/baselines/reference/letDeclarations-scopes-duplicates7.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1+
tests/cases/compiler/file1.ts(2,5): error TS2300: Duplicate identifier 'var1'.
12
tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'.
23

34

4-
==== tests/cases/compiler/file1.ts (0 errors) ====
5+
==== tests/cases/compiler/file1.ts (1 errors) ====
56

67
let var1 = 0;
8+
~~~~
9+
!!! error TS2300: Duplicate identifier 'var1'.
710

811
==== tests/cases/compiler/file2.ts (1 errors) ====
912
var var1 = 0;

tests/baselines/reference/letDeclarations3.errors.txt

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

tests/baselines/reference/parserOptionalTypeMembers1.errors.txt

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

tests/baselines/reference/parserOptionalTypeMembers1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//// [parserOptionalTypeMembers1.ts]
2-
interface PropertyDescriptor {
2+
interface PropertyDescriptor2 {
33
configurable?: boolean;
44
enumerable?: boolean;
55
value?: any;
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
=== tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts ===
2+
interface PropertyDescriptor2 {
3+
>PropertyDescriptor2 : PropertyDescriptor2
4+
5+
configurable?: boolean;
6+
>configurable : boolean
7+
8+
enumerable?: boolean;
9+
>enumerable : boolean
10+
11+
value?: any;
12+
>value : any
13+
14+
writable?: boolean;
15+
>writable : boolean
16+
17+
get?(): any;
18+
>get : () => any
19+
20+
set?(v: any): void;
21+
>set : (v: any) => void
22+
>v : any
23+
}

tests/baselines/reference/project/declareVariableCollision/amd/declareVariableCollision.errors.txt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
in1.d.ts(1,8): error TS2300: Duplicate identifier 'a'.
12
in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'.
23

34

@@ -14,8 +15,10 @@ in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'.
1415
class MyClass{ }
1516
}
1617
}
17-
==== in1.d.ts (0 errors) ====
18+
==== in1.d.ts (1 errors) ====
1819
import a = A;
20+
~
21+
!!! error TS2300: Duplicate identifier 'a'.
1922
==== in2.d.ts (1 errors) ====
2023
import a = A;
2124
~

0 commit comments

Comments
 (0)