From a07f86240d7ca9af9e77bdd45caf3b0ad4396adf Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Wed, 17 Jun 2015 15:01:34 -0700 Subject: [PATCH] forbid calling abstract member foo() via super.foo() --- src/compiler/checker.ts | 14 ++++++++++++-- src/compiler/diagnosticInformationMap.generated.ts | 3 ++- src/compiler/diagnosticMessages.json | 6 +++++- 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 242793c8b6b..fac2ee3b4c5 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6714,8 +6714,18 @@ 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) { - error(right, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); + 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); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index ba617d9cf3b..d1cd9b4ba39 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -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}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 91d1eafb998..ddfc885dcf6 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -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