Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
plantain-00 committed Jun 16, 2016
1 parent 95ae809 commit dad73ed
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 1 deletion.
17 changes: 17 additions & 0 deletions src/compiler/checker.ts
Expand Up @@ -13161,6 +13161,8 @@ namespace ts {
checkGrammarDecorators(node) || checkGrammarModifiers(node) || checkGrammarProperty(node) || checkGrammarComputedPropertyName(node.name);

checkVariableLikeDeclaration(node);

checkNameOfStaticMethodOrPropertyInClass(node);
}

function checkMethodDeclaration(node: MethodDeclaration) {
Expand All @@ -13175,6 +13177,21 @@ namespace ts {
if (node.flags & NodeFlags.Abstract && node.body) {
error(node, Diagnostics.Method_0_cannot_have_an_implementation_because_it_is_marked_abstract, declarationNameToString(node.name));
}

checkNameOfStaticMethodOrPropertyInClass(node);
}

function checkNameOfStaticMethodOrPropertyInClass(node: ClassElement) {
if (node.flags & NodeFlags.Static) {
const name = (node.name as Identifier).text;
switch (name) {
case "length":
case "name":
case "arguments":
case "caller":
error(node, Diagnostics._0_is_not_allowed_to_be_used_as_a_name_of_a_static_property_or_method_in_a_class, name);
}
}
}

function checkConstructorDeclaration(node: ConstructorDeclaration) {
Expand Down
4 changes: 4 additions & 0 deletions src/compiler/diagnosticMessages.json
Expand Up @@ -1935,6 +1935,10 @@
"category": "Error",
"code": 2688
},
"'{0}' is not allowed to be used as a name of a static property or method in a class.": {
"category": "Error",
"code": 2689
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",
"code": 4000
Expand Down
@@ -1,3 +1,4 @@
tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts(8,19): error TS2689: 'name' is not allowed to be used as a name of a static property or method in a class.
tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts(12,1): error TS2322: Type 'C' is not assignable to type 'A'.
Property 'name' is missing in type 'C'.
tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts(13,1): error TS2322: Type 'typeof B' is not assignable to type 'A'.
Expand All @@ -8,7 +9,7 @@ tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.
Property 'name' is missing in type 'typeof B'.


==== tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts (4 errors) ====
==== tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.ts (5 errors) ====
interface A {
name();
}
Expand All @@ -17,6 +18,8 @@ tests/cases/compiler/staticMemberOfClassAndPublicMemberOfAnotherClassAssignment.
}
class C {
public static name() { }
~~~~
!!! error TS2689: 'name' is not allowed to be used as a name of a static property or method in a class.
}

var a: A = new B();
Expand Down

0 comments on commit dad73ed

Please sign in to comment.