From b623f3771e91f5fe31c498c9a5defc4172b567bd Mon Sep 17 00:00:00 2001 From: about-code Date: Wed, 9 Nov 2016 21:08:56 +0100 Subject: [PATCH] Fix #442: (es3, es5, es6+) Show compiler errors for conflicting properties. --- src/compiler/checker.ts | 6 ++++-- .../staticPropertyNameConflictsEs6.errors.txt | 14 ++++++++++---- .../reference/staticPropertyNameConflictsEs6.js | 6 +++--- .../staticPropertyNameConflictsEs6.ts | 6 +++--- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index d756f215ac..de82ee004e 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -14794,11 +14794,13 @@ namespace ts { error(memberNameNode, message, memberName, className); } else if (( + memberName === "name" || + memberName === "length" || memberName === "caller" || - memberName === "arguments" ) && + memberName === "arguments") && isMethod === false ) { - error(memberNameNode, message, memberName, className); + error(memberNameNode, message, memberName, className); } } } diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt b/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt index b73b01abbb..607735bb12 100644 --- a/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt +++ b/tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt @@ -1,3 +1,5 @@ +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(4,12): error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. +tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(15,12): error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(26,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototype'. tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2300: Duplicate identifier 'prototype'. tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2699: Static property 'prototype' conflicts with built-in property 'Function.prototype' of constructor function 'StaticPrototypeFn'. @@ -5,22 +7,26 @@ tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameCon tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(48,12): error TS2699: Static property 'arguments' conflicts with built-in property 'Function.arguments' of constructor function 'StaticArguments'. -==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts (5 errors) ==== +==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts (7 errors) ==== class StaticName { - static name: number; // ok + static name: number; // error + ~~~~ +!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'. name: string; // ok } class StaticNameFn { - static name() {} // ok + static name() {} // ok name() {} // ok } class StaticLength { - static length: number; // ok + static length: number; // error + ~~~~~~ +!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'. length: string; // ok } diff --git a/tests/baselines/reference/staticPropertyNameConflictsEs6.js b/tests/baselines/reference/staticPropertyNameConflictsEs6.js index 8d96c73d4c..7adef10b14 100644 --- a/tests/baselines/reference/staticPropertyNameConflictsEs6.js +++ b/tests/baselines/reference/staticPropertyNameConflictsEs6.js @@ -2,18 +2,18 @@ class StaticName { - static name: number; // ok + static name: number; // error name: string; // ok } class StaticNameFn { - static name() {} // ok + static name() {} // ok name() {} // ok } class StaticLength { - static length: number; // ok + static length: number; // error length: string; // ok } diff --git a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts index 01db0c2787..1b93e98dae 100644 --- a/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts +++ b/tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts @@ -2,18 +2,18 @@ class StaticName { - static name: number; // ok + static name: number; // error name: string; // ok } class StaticNameFn { - static name() {} // ok + static name() {} // ok name() {} // ok } class StaticLength { - static length: number; // ok + static length: number; // error length: string; // ok }