From ce629f03a7334963ac724146a680aa758e517049 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Tue, 31 Jan 2017 14:16:25 -0800 Subject: [PATCH] Test duplicate identifier reporting in classes --- .../classWithDuplicateIdentifier.errors.txt | 31 +++++++++++++++++ .../reference/classWithDuplicateIdentifier.js | 33 +++++++++++++++++++ .../compiler/classWithDuplicateIdentifier.ts | 12 +++++++ 3 files changed, 76 insertions(+) create mode 100644 tests/baselines/reference/classWithDuplicateIdentifier.errors.txt create mode 100644 tests/baselines/reference/classWithDuplicateIdentifier.js create mode 100644 tests/cases/compiler/classWithDuplicateIdentifier.ts diff --git a/tests/baselines/reference/classWithDuplicateIdentifier.errors.txt b/tests/baselines/reference/classWithDuplicateIdentifier.errors.txt new file mode 100644 index 00000000000..325db86d47d --- /dev/null +++ b/tests/baselines/reference/classWithDuplicateIdentifier.errors.txt @@ -0,0 +1,31 @@ +tests/cases/compiler/classWithDuplicateIdentifier.ts(3,5): error TS2300: Duplicate identifier 'a'. +tests/cases/compiler/classWithDuplicateIdentifier.ts(6,5): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/classWithDuplicateIdentifier.ts(7,5): error TS2300: Duplicate identifier 'b'. +tests/cases/compiler/classWithDuplicateIdentifier.ts(11,5): error TS2300: Duplicate identifier 'c'. +tests/cases/compiler/classWithDuplicateIdentifier.ts(11,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'number', but here has type 'string'. + + +==== tests/cases/compiler/classWithDuplicateIdentifier.ts (5 errors) ==== + class C { + a(): number { return 0; } // error: duplicate identifier + a: number; + ~ +!!! error TS2300: Duplicate identifier 'a'. + } + class K { + b: number; // error: duplicate identifier + ~ +!!! error TS2300: Duplicate identifier 'b'. + b(): number { return 0; } + ~ +!!! error TS2300: Duplicate identifier 'b'. + } + class D { + c: number; + c: string; + ~ +!!! error TS2300: Duplicate identifier 'c'. + ~ +!!! error TS2403: Subsequent variable declarations must have the same type. Variable 'c' must be of type 'number', but here has type 'string'. + } + \ No newline at end of file diff --git a/tests/baselines/reference/classWithDuplicateIdentifier.js b/tests/baselines/reference/classWithDuplicateIdentifier.js new file mode 100644 index 00000000000..515b1749aa3 --- /dev/null +++ b/tests/baselines/reference/classWithDuplicateIdentifier.js @@ -0,0 +1,33 @@ +//// [classWithDuplicateIdentifier.ts] +class C { + a(): number { return 0; } // error: duplicate identifier + a: number; +} +class K { + b: number; // error: duplicate identifier + b(): number { return 0; } +} +class D { + c: number; + c: string; +} + + +//// [classWithDuplicateIdentifier.js] +var C = (function () { + function C() { + } + C.prototype.a = function () { return 0; }; // error: duplicate identifier + return C; +}()); +var K = (function () { + function K() { + } + K.prototype.b = function () { return 0; }; + return K; +}()); +var D = (function () { + function D() { + } + return D; +}()); diff --git a/tests/cases/compiler/classWithDuplicateIdentifier.ts b/tests/cases/compiler/classWithDuplicateIdentifier.ts new file mode 100644 index 00000000000..1612bd3f378 --- /dev/null +++ b/tests/cases/compiler/classWithDuplicateIdentifier.ts @@ -0,0 +1,12 @@ +class C { + a(): number { return 0; } // error: duplicate identifier + a: number; +} +class K { + b: number; // error: duplicate identifier + b(): number { return 0; } +} +class D { + c: number; + c: string; +}