Skip to content

Commit

Permalink
Report duplicate identifier errors on all locations for merged declar…
Browse files Browse the repository at this point in the history
…ations to align with local declarations
  • Loading branch information
mhegazy committed Oct 14, 2014
1 parent 318575c commit cffc62a
Show file tree
Hide file tree
Showing 21 changed files with 161 additions and 129 deletions.
3 changes: 3 additions & 0 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ module ts {
forEach(source.declarations, node => {
error(node.name ? node.name : node, Diagnostics.Duplicate_identifier_0, symbolToString(source));
});
forEach(target.declarations, node => {
error(node.name ? node.name : node, Diagnostics.Duplicate_identifier_0, symbolToString(source));
});

This comment has been minimized.

Copy link
@ahejlsberg

ahejlsberg Oct 17, 2014

Member

I like that we're now doing this. So, if for example I declare my own Array<T> with a length property I would see a duplicate error both on my declaration and the one in lib.d.ts, right? I can't tell from the tests below.

Should we also be doing this for declarations that are merged during local binding?

This comment has been minimized.

Copy link
@mhegazy

mhegazy Oct 17, 2014

Author Contributor

yes. @yuit checked in a fix for the local declarations. this is to ensure we are getting the same behavior while merging across files. so errors will be reported in lib.d.ts for a module "Array" and for redefining a property "length" in interface "Array"

}
}

Expand Down

This file was deleted.

23 changes: 14 additions & 9 deletions tests/baselines/reference/functionTypeArgumentArrayAssignment.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
//// [functionTypeArgumentArrayAssignment.ts]
interface Array<T> {
foo: T;
length: number;
}
module test {
interface Array<T> {
foo: T;
length: number;
}

function map<U>() {
var ys: U[] = [];
function map<U>() {
var ys: U[] = [];
}
}


//// [functionTypeArgumentArrayAssignment.js]
function map() {
var ys = [];
}
var test;
(function (test) {
function map() {
var ys = [];
}
})(test || (test = {}));
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
=== tests/cases/compiler/functionTypeArgumentArrayAssignment.ts ===
module test {
>test : typeof test

interface Array<T> {
>Array : Array<T>
>T : T

foo: T;
>foo : T
>T : T

length: number;
>length : number
}

function map<U>() {
>map : <U>() => void
>U : U

var ys: U[] = [];
>ys : U[]
>U : U
>[] : U[]
}
}

47 changes: 23 additions & 24 deletions tests/baselines/reference/instanceofOperator.errors.txt
Original file line number Diff line number Diff line change
@@ -1,43 +1,42 @@
tests/cases/compiler/instanceofOperator.ts(6,7): error TS2300: Duplicate identifier 'Object'.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.


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

class Object { }
~~~~~~
!!! error TS2300: Duplicate identifier 'Object'.
var obj: Object;
module test {
class Object { }
var obj: Object;



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

// Error and should be error
obj instanceof 4;
~
// Error and should be error
obj instanceof 4;
~
!!! 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.
Object instanceof obj;
~~~
Object instanceof obj;
~~~
!!! 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.

// Error on left hand side
null instanceof null;
~~~~
// Error on left hand side
null instanceof null;
~~~~
!!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
obj instanceof Object;
undefined instanceof undefined;
~~~~~~~~~
obj instanceof Object;
undefined instanceof undefined;
~~~~~~~~~
!!! error TS2358: The left-hand side of an 'instanceof' expression must be of type 'any', an object type or a type parameter.
}


53 changes: 29 additions & 24 deletions tests/baselines/reference/instanceofOperator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,23 @@
// operand to be of type Any or a subtype of the ‘Function’ interface type. The result is always of the
// Boolean primitive type.

class Object { }
var obj: Object;
module test {
class Object { }
var obj: Object;



4 instanceof null;
4 instanceof null;

// Error and should be error
obj instanceof 4;
Object instanceof obj;
// Error and should be error
obj instanceof 4;
Object instanceof obj;

// Error on left hand side
null instanceof null;
obj instanceof Object;
undefined instanceof undefined;
// Error on left hand side
null instanceof null;
obj instanceof Object;
undefined instanceof undefined;
}



Expand All @@ -27,17 +29,20 @@ undefined instanceof undefined;
// The instanceof operator requires the left operand to be of type Any or an object type, and the right
// operand to be of type Any or a subtype of the ‘Function’ interface type. The result is always of the
// Boolean primitive type.
var Object = (function () {
function Object() {
}
return Object;
})();
var obj;
4 instanceof null;
// Error and should be error
obj instanceof 4;
Object instanceof obj;
// Error on left hand side
null instanceof null;
obj instanceof Object;
undefined instanceof undefined;
var test;
(function (test) {
var Object = (function () {
function Object() {
}
return Object;
})();
var obj;
4 instanceof null;
// Error and should be error
obj instanceof 4;
Object instanceof obj;
// Error on left hand side
null instanceof null;
obj instanceof Object;
undefined instanceof undefined;
})(test || (test = {}));
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
tests/cases/compiler/file1.ts(2,5): error TS2300: Duplicate identifier 'var1'.
tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'.


==== tests/cases/compiler/file1.ts (0 errors) ====
==== tests/cases/compiler/file1.ts (1 errors) ====

let var1 = 0;
~~~~
!!! error TS2300: Duplicate identifier 'var1'.

==== tests/cases/compiler/file2.ts (1 errors) ====
let var1 = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
tests/cases/compiler/file1.ts(2,5): error TS2300: Duplicate identifier 'var1'.
tests/cases/compiler/file2.ts(1,7): error TS2300: Duplicate identifier 'var1'.


==== tests/cases/compiler/file1.ts (0 errors) ====
==== tests/cases/compiler/file1.ts (1 errors) ====

let var1 = 0;
~~~~
!!! error TS2300: Duplicate identifier 'var1'.

==== tests/cases/compiler/file2.ts (1 errors) ====
const var1 = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
tests/cases/compiler/file1.ts(2,7): error TS2300: Duplicate identifier 'var1'.
tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'.


==== tests/cases/compiler/file1.ts (0 errors) ====
==== tests/cases/compiler/file1.ts (1 errors) ====

const var1 = 0;
~~~~
!!! error TS2300: Duplicate identifier 'var1'.

==== tests/cases/compiler/file2.ts (1 errors) ====
let var1 = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
tests/cases/compiler/file1.ts(2,7): error TS2300: Duplicate identifier 'var1'.
tests/cases/compiler/file2.ts(1,7): error TS2300: Duplicate identifier 'var1'.


==== tests/cases/compiler/file1.ts (0 errors) ====
==== tests/cases/compiler/file1.ts (1 errors) ====

const var1 = 0;
~~~~
!!! error TS2300: Duplicate identifier 'var1'.

==== tests/cases/compiler/file2.ts (1 errors) ====
const var1 = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
tests/cases/compiler/file1.ts(2,5): error TS2300: Duplicate identifier 'var1'.
tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'.


==== tests/cases/compiler/file1.ts (0 errors) ====
==== tests/cases/compiler/file1.ts (1 errors) ====

var var1 = 0;
~~~~
!!! error TS2300: Duplicate identifier 'var1'.

==== tests/cases/compiler/file2.ts (1 errors) ====
let var1 = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
tests/cases/compiler/file1.ts(2,5): error TS2300: Duplicate identifier 'var1'.
tests/cases/compiler/file2.ts(1,5): error TS2300: Duplicate identifier 'var1'.


==== tests/cases/compiler/file1.ts (0 errors) ====
==== tests/cases/compiler/file1.ts (1 errors) ====

let var1 = 0;
~~~~
!!! error TS2300: Duplicate identifier 'var1'.

==== tests/cases/compiler/file2.ts (1 errors) ====
var var1 = 0;
Expand Down
18 changes: 0 additions & 18 deletions tests/baselines/reference/letDeclarations3.errors.txt

This file was deleted.

23 changes: 0 additions & 23 deletions tests/baselines/reference/parserOptionalTypeMembers1.errors.txt

This file was deleted.

2 changes: 1 addition & 1 deletion tests/baselines/reference/parserOptionalTypeMembers1.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//// [parserOptionalTypeMembers1.ts]
interface PropertyDescriptor {
interface PropertyDescriptor2 {
configurable?: boolean;
enumerable?: boolean;
value?: any;
Expand Down
23 changes: 23 additions & 0 deletions tests/baselines/reference/parserOptionalTypeMembers1.types
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
=== tests/cases/conformance/parser/ecmascript5/parserOptionalTypeMembers1.ts ===
interface PropertyDescriptor2 {
>PropertyDescriptor2 : PropertyDescriptor2

configurable?: boolean;
>configurable : boolean

enumerable?: boolean;
>enumerable : boolean

value?: any;
>value : any

writable?: boolean;
>writable : boolean

get?(): any;
>get : () => any

set?(v: any): void;
>set : (v: any) => void
>v : any
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
in1.d.ts(1,8): error TS2300: Duplicate identifier 'a'.
in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'.


Expand All @@ -14,8 +15,10 @@ in2.d.ts(1,8): error TS2300: Duplicate identifier 'a'.
class MyClass{ }
}
}
==== in1.d.ts (0 errors) ====
==== in1.d.ts (1 errors) ====
import a = A;
~
!!! error TS2300: Duplicate identifier 'a'.
==== in2.d.ts (1 errors) ====
import a = A;
~
Expand Down
Loading

0 comments on commit cffc62a

Please sign in to comment.