forbid calling abstract member foo() via super.foo()
This commit is contained in:
parent
388e2fd926
commit
a07f86240d
3 changed files with 19 additions and 4 deletions
|
@ -6714,9 +6714,19 @@ namespace ts {
|
|||
// - In a static member function or static member accessor
|
||||
// where this references the constructor function object of a derived class,
|
||||
// a super property access is permitted and must specify a public static member function of the base class.
|
||||
if (left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) {
|
||||
if (left.kind === SyntaxKind.SuperKeyword) {
|
||||
if (getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) {
|
||||
error(right, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword);
|
||||
}
|
||||
|
||||
// Abstract methods cannot be accessed through super property accesses. Eg:
|
||||
// class A { abstract foo(); }
|
||||
// class B extends A { bar() { super.foo();} }
|
||||
// is illegal.
|
||||
if (getDeclarationFlagsFromSymbol(prop) & NodeFlags.Abstract) {
|
||||
error(right, Diagnostics.Abstract_member_function_0_on_type_1_cannot_be_called_via_super_expression, declarationNameToString(right), typeToString(type));
|
||||
}
|
||||
}
|
||||
else {
|
||||
checkClassPropertyAccess(node, left, type, prop);
|
||||
}
|
||||
|
|
|
@ -393,8 +393,9 @@ namespace ts {
|
|||
No_base_constructor_has_the_specified_number_of_type_arguments: { code: 2508, category: DiagnosticCategory.Error, key: "No base constructor has the specified number of type arguments." },
|
||||
Base_constructor_does_not_return_a_class_or_interface_type: { code: 2509, category: DiagnosticCategory.Error, key: "Base constructor does not return a class or interface type." },
|
||||
Base_constructors_must_all_have_the_same_return_type: { code: 2510, category: DiagnosticCategory.Error, key: "Base constructors must all have the same return type." },
|
||||
Cannot_create_an_instance_of_the_abstract_class_0: { code: 2511, category: DiagnosticCategory.Error, key: "Cannot create an instance of the abstract class '{0}'" },
|
||||
Cannot_create_an_instance_of_the_abstract_class_0: { code: 2511, category: DiagnosticCategory.Error, key: "Cannot create an instance of the abstract class '{0}'." },
|
||||
All_overload_signatures_must_match_with_respect_to_modifier_0: { code: 2512, category: DiagnosticCategory.Error, key: "All overload signatures must match with respect to modifier '{0}'." },
|
||||
Abstract_member_function_0_on_type_1_cannot_be_called_via_super_expression: { code: 2513, category: DiagnosticCategory.Error, key: "Abstract member function '{0}' on type '{1}' cannot be called via super expression." },
|
||||
Import_declaration_0_is_using_private_name_1: { code: 4000, category: DiagnosticCategory.Error, key: "Import declaration '{0}' is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 4002, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using private name '{1}'." },
|
||||
Type_parameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 4004, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported interface has or is using private name '{1}'." },
|
||||
|
|
|
@ -1559,7 +1559,7 @@
|
|||
"category": "Error",
|
||||
"code": 2510
|
||||
},
|
||||
"Cannot create an instance of the abstract class '{0}'": {
|
||||
"Cannot create an instance of the abstract class '{0}'.": {
|
||||
"category": "Error",
|
||||
"code": 2511
|
||||
},
|
||||
|
@ -1567,6 +1567,10 @@
|
|||
"category": "Error",
|
||||
"code": 2512
|
||||
},
|
||||
"Abstract member function '{0}' on type '{1}' cannot be called via super expression.": {
|
||||
"category": "Error",
|
||||
"code": 2513
|
||||
},
|
||||
"Import declaration '{0}' is using private name '{1}'.": {
|
||||
"category": "Error",
|
||||
"code": 4000
|
||||
|
|
Loading…
Reference in a new issue