From 5c0b913b271cf94d8a62f9bd56adf9c7df09b78c Mon Sep 17 00:00:00 2001 From: Arthur Ozga Date: Mon, 22 Jun 2015 15:47:12 -0700 Subject: [PATCH] changed error messages and fixed comments --- src/compiler/checker.ts | 37 +++++++++++-------- .../diagnosticInformationMap.generated.ts | 10 ++--- src/compiler/diagnosticMessages.json | 10 ++--- 3 files changed, 31 insertions(+), 26 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 34928296570..5b1479bbf31 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -6693,18 +6693,21 @@ 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 (getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) { // prop is a property access. + if (getDeclarationKindFromSymbol(prop) !== SyntaxKind.MethodDeclaration) { + // `prop` refers to a *property* declared in the super class + // rather than a *method*, so it does not satisfy the above criteria. + error(errorNode, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); return false; } - - // In a super call, the member function can be accessed if the method is not abstract. + + // In a super call, the methods cannot be accessed if the method is abstract. // Note that a member cannot be private and abstract -- this is checked elsewhere. if (flags & NodeFlags.Abstract) { // Get the declaring the class instance type for the error message. declaringClass = getDeclaredTypeOfSymbol(prop.parent); - error(errorNode, Diagnostics.Abstract_member_function_0_on_type_1_cannot_be_called_via_super_expression, symbolToString(prop), typeToString(declaringClass)); + error(errorNode, Diagnostics.Abstract_method_0_1_cannot_be_called_via_super_expression, symbolToString(prop), typeToString(declaringClass)); return false; } } @@ -9142,7 +9145,7 @@ namespace ts { error(signatureDeclarationNode, Diagnostics.Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature); } - function getEffectiveDeclarationFlags(n: Node, flagsToCheck: NodeFlags) { + function getEffectiveDeclarationFlags(n: Node, flagsToCheck: NodeFlags) : NodeFlags { let flags = getCombinedNodeFlags(n); if (n.parent.kind !== SyntaxKind.InterfaceDeclaration && isInAmbientContext(n)) { if (!(flags & NodeFlags.Ambient)) { @@ -9189,7 +9192,7 @@ namespace ts { error(o.name, Diagnostics.Overload_signatures_must_all_be_public_private_or_protected); } else if (deviation & NodeFlags.Abstract) { - error(o.name, Diagnostics.All_overload_signatures_must_match_with_respect_to_modifier_0, "abstract"); + error(o.name, Diagnostics.Overload_signatures_must_all_be_abstract_or_not_abstract, "abstract"); } }); } @@ -9260,7 +9263,7 @@ namespace ts { // Report different errors regarding non-consecutive blocks of declarations depending on whether // the node in question is abstract. if (node.flags & NodeFlags.Abstract) { - error(errorNode, Diagnostics.All_declarations_of_an_abstract_member_function_must_be_consecutive); + error(errorNode, Diagnostics.All_declarations_of_an_abstract_method_must_be_consecutive); } else { error(errorNode, Diagnostics.Function_implementation_is_missing_or_not_immediately_following_the_declaration); @@ -9312,9 +9315,10 @@ namespace ts { bodyDeclaration = node; } - // abstract functions cannot have an implementation - if (currentNodeFlags & NodeFlags.Abstract) { - error(node, Diagnostics.Abstract_member_functions_cannot_have_an_implementation) + // abstract functions cannot have an implementation. + // Extra checks are to avoid reporting multiple errors relating to the "abstractness" of the node. + if (currentNodeFlags & NodeFlags.Abstract && node.kind === SyntaxKind.MethodDeclaration && !isConstructor) { + error(node, Diagnostics.Method_0_cannot_have_an_implementation_because_it_is_marked_abstract, declarationNameToString(node.name)) } } else { @@ -9561,7 +9565,7 @@ namespace ts { case SyntaxKind.MethodDeclaration: checkParameterTypeAnnotationsAsExpressions(node); - // Otherwise fall through + // Fall through case SyntaxKind.SetAccessor: case SyntaxKind.GetAccessor: @@ -10725,11 +10729,12 @@ namespace ts { } forEach(node.members, checkSourceElement); - - // Classes containing abstract members must be marked abstract - if (!(node.flags & NodeFlags.Abstract) && forEach(node.members, (element: ClassElement) => element.flags & NodeFlags.Abstract)) { + + // Classes containing abstract methods must be marked abstract + if (!(node.flags & NodeFlags.Abstract) && forEach(node.members, element => element.flags & NodeFlags.Abstract)) { error(node, Diagnostics.Classes_containing_abstract_functions_must_be_marked_abstract); } + if (produceDiagnostics) { checkIndexConstraints(type); checkTypeForDuplicateIndexSignatures(node); @@ -12074,7 +12079,7 @@ namespace ts { (node.parent).moduleSpecifier === node)) { return resolveExternalModuleName(node, node); } - // Otherwise fall through + // Fall through case SyntaxKind.NumericLiteral: // index access @@ -12880,7 +12885,7 @@ namespace ts { } if (node.kind !== SyntaxKind.ClassDeclaration) { if (node.kind !== SyntaxKind.MethodDeclaration) { - return grammarErrorOnNode(modifier, Diagnostics._0_modifier_can_only_appear_on_a_class_or_member_function_declaration, "abstract"); + return grammarErrorOnNode(modifier, Diagnostics.abstract_modifier_can_only_appear_on_a_class_or_method_declaration); } if (!(node.parent.kind === SyntaxKind.ClassDeclaration && node.parent.flags & NodeFlags.Abstract)) { return grammarErrorOnNode(modifier, Diagnostics.Abstract_methods_can_only_appear_within_an_abstract_class); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 343b4e22738..572c83849e5 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -191,10 +191,10 @@ namespace ts { An_export_declaration_can_only_be_used_in_a_module: { code: 1233, category: DiagnosticCategory.Error, key: "An export declaration can only be used in a module." }, An_ambient_module_declaration_is_only_allowed_at_the_top_level_in_a_file: { code: 1234, category: DiagnosticCategory.Error, key: "An ambient module declaration is only allowed at the top level in a file." }, A_namespace_declaration_is_only_allowed_in_a_namespace_or_module: { code: 1235, category: DiagnosticCategory.Error, key: "A namespace declaration is only allowed in a namespace or module." }, - _0_modifier_can_only_appear_on_a_class_or_member_function_declaration: { code: 1236, category: DiagnosticCategory.Error, key: "'{0}' modifier can only appear on a class or member function declaration." }, + abstract_modifier_can_only_appear_on_a_class_or_method_declaration: { code: 1236, category: DiagnosticCategory.Error, key: "'abstract' modifier can only appear on a class or method declaration." }, _0_modifier_cannot_be_used_with_1_modifier: { code: 1237, category: DiagnosticCategory.Error, key: "'{0}' modifier cannot be used with '{1}' modifier." }, Abstract_methods_can_only_appear_within_an_abstract_class: { code: 1238, category: DiagnosticCategory.Error, key: "Abstract methods can only appear within an abstract class." }, - Abstract_member_functions_cannot_have_an_implementation: { code: 1240, category: DiagnosticCategory.Error, key: "Abstract member functions cannot have an implementation." }, + Method_0_cannot_have_an_implementation_because_it_is_marked_abstract: { code: 1240, category: DiagnosticCategory.Error, key: "Method '{0}' cannot have an implementation because it is marked abstract." }, Duplicate_identifier_0: { code: 2300, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." }, Initializer_of_instance_member_variable_0_cannot_reference_identifier_1_declared_in_the_constructor: { code: 2301, category: DiagnosticCategory.Error, key: "Initializer of instance member variable '{0}' cannot reference identifier '{1}' declared in the constructor." }, Static_members_cannot_reference_class_type_parameters: { code: 2302, category: DiagnosticCategory.Error, key: "Static members cannot reference class type parameters." }, @@ -394,11 +394,11 @@ namespace ts { Base_constructor_return_type_0_is_not_a_class_or_interface_type: { code: 2509, category: DiagnosticCategory.Error, key: "Base constructor return type '{0}' is not 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}'." }, - 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." }, + Overload_signatures_must_all_be_abstract_or_not_abstract: { code: 2512, category: DiagnosticCategory.Error, key: "Overload signatures must all be `abstract` or not `abstract." }, + Abstract_method_0_1_cannot_be_called_via_super_expression: { code: 2513, category: DiagnosticCategory.Error, key: "Abstract method '{0}.{1}' cannot be called via super expression." }, Classes_containing_abstract_functions_must_be_marked_abstract: { code: 2514, category: DiagnosticCategory.Error, key: "Classes containing abstract functions must be marked abstract." }, Non_abstract_class_0_does_not_implement_inherited_abstract_member_1_2: { code: 2515, category: DiagnosticCategory.Error, key: "Non-abstract class '{0}' does not implement inherited abstract member '{1}.{2}'." }, - All_declarations_of_an_abstract_member_function_must_be_consecutive: { code: 2516, category: DiagnosticCategory.Error, key: "All declarations of an abstract member function must be consecutive." }, + All_declarations_of_an_abstract_method_must_be_consecutive: { code: 2516, category: DiagnosticCategory.Error, key: "All declarations of an abstract method must be consecutive." }, 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 8df76ec8961..425aa5e87ac 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -751,7 +751,7 @@ "category": "Error", "code": 1235 }, - "'{0}' modifier can only appear on a class or member function declaration.": { + "'abstract' modifier can only appear on a class or method declaration.": { "category": "Error", "code": 1236 }, @@ -763,7 +763,7 @@ "category": "Error", "code": 1238 }, - "Abstract member functions cannot have an implementation.": { + "Method '{0}' cannot have an implementation because it is marked abstract.": { "category": "Error", "code": 1240 }, @@ -1563,11 +1563,11 @@ "category": "Error", "code": 2511 }, - "All overload signatures must match with respect to modifier '{0}'.": { + "Overload signatures must all be `abstract` or not `abstract.": { "category": "Error", "code": 2512 }, - "Abstract member function '{0}' on type '{1}' cannot be called via super expression.": { + "Abstract method '{0}.{1}' cannot be called via super expression.": { "category": "Error", "code": 2513 }, @@ -1579,7 +1579,7 @@ "category": "Error", "code": 2515 }, - "All declarations of an abstract member function must be consecutive.": { + "All declarations of an abstract method must be consecutive.": { "category": "Error", "code": 2516 },