Skip to content

Commit b623f37

Browse files
committed
Fix #442: (es3, es5, es6+) Show compiler errors for conflicting properties.
1 parent d9a46e1 commit b623f37

File tree

4 files changed

+20
-12
lines changed

4 files changed

+20
-12
lines changed

src/compiler/checker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14794,11 +14794,13 @@ namespace ts {
1479414794
error(memberNameNode, message, memberName, className);
1479514795
}
1479614796
else if ((
14797+
memberName === "name" ||
14798+
memberName === "length" ||
1479714799
memberName === "caller" ||
14798-
memberName === "arguments" ) &&
14800+
memberName === "arguments") &&
1479914801
isMethod === false
1480014802
) {
14801-
error(memberNameNode, message, memberName, className);
14803+
error(memberNameNode, message, memberName, className);
1480214804
}
1480314805
}
1480414806
}

tests/baselines/reference/staticPropertyNameConflictsEs6.errors.txt

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,32 @@
1+
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'.
2+
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'.
13
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'.
24
tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(31,12): error TS2300: Duplicate identifier 'prototype'.
35
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'.
46
tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts(37,12): error TS2699: Static property 'caller' conflicts with built-in property 'Function.caller' of constructor function 'StaticCaller'.
57
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'.
68

79

8-
==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts (5 errors) ====
10+
==== tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts (7 errors) ====
911

1012

1113
class StaticName {
12-
static name: number; // ok
14+
static name: number; // error
15+
~~~~
16+
!!! error TS2699: Static property 'name' conflicts with built-in property 'Function.name' of constructor function 'StaticName'.
1317
name: string; // ok
1418
}
1519

1620
class StaticNameFn {
17-
static name() {} // ok
21+
static name() {} // ok
1822
name() {} // ok
1923
}
2024

2125

2226
class StaticLength {
23-
static length: number; // ok
27+
static length: number; // error
28+
~~~~~~
29+
!!! error TS2699: Static property 'length' conflicts with built-in property 'Function.length' of constructor function 'StaticLength'.
2430
length: string; // ok
2531
}
2632

tests/baselines/reference/staticPropertyNameConflictsEs6.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33

44
class StaticName {
5-
static name: number; // ok
5+
static name: number; // error
66
name: string; // ok
77
}
88

99
class StaticNameFn {
10-
static name() {} // ok
10+
static name() {} // ok
1111
name() {} // ok
1212
}
1313

1414

1515
class StaticLength {
16-
static length: number; // ok
16+
static length: number; // error
1717
length: string; // ok
1818
}
1919

tests/cases/conformance/classes/propertyMemberDeclarations/staticPropertyNameConflictsEs6.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,18 @@
22

33

44
class StaticName {
5-
static name: number; // ok
5+
static name: number; // error
66
name: string; // ok
77
}
88

99
class StaticNameFn {
10-
static name() {} // ok
10+
static name() {} // ok
1111
name() {} // ok
1212
}
1313

1414

1515
class StaticLength {
16-
static length: number; // ok
16+
static length: number; // error
1717
length: string; // ok
1818
}
1919

0 commit comments

Comments
 (0)