From ce6b6234ef823b7d6c9ff00c913d663779b3165f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 17 Sep 2014 10:36:32 -0700 Subject: [PATCH 1/5] Support for protected members in classes --- src/compiler/binder.ts | 2 +- src/compiler/checker.ts | 184 +++++++++++------- .../diagnosticInformationMap.generated.ts | 11 +- src/compiler/diagnosticMessages.json | 21 +- src/compiler/emitter.ts | 10 +- src/compiler/parser.ts | 27 ++- src/compiler/types.ts | 11 +- ...tWithObjectMembersAccessibility.errors.txt | 48 ++--- ...patWithObjectMembersOptionality.errors.txt | 12 +- .../assignmentCompatability10.errors.txt | 2 +- .../assignmentCompatability13.errors.txt | 2 +- .../assignmentCompatability27.errors.txt | 2 +- .../assignmentCompatability39.errors.txt | 2 +- .../assignmentCompatability40.errors.txt | 2 +- .../assignmentCompatability41.errors.txt | 2 +- .../assignmentCompatability42.errors.txt | 2 +- .../assignmentCompatability43.errors.txt | 2 +- ...ceThatExtendsClassWithPrivates1.errors.txt | 2 +- .../classImplementsClass5.errors.txt | 6 +- .../classIsSubtypeOfBaseType.errors.txt | 2 +- .../reference/classUpdateTests.errors.txt | 4 +- ...dClassOverridesPrivateFunction1.errors.txt | 2 +- .../derivedClassOverridesPrivates.errors.txt | 4 +- ...InstanceShadowingPublicInstance.errors.txt | 2 +- ...vateStaticShadowingPublicStatic.errors.txt | 2 +- .../errorSuperPropertyAccess.errors.txt | 28 +-- .../functionOverloadErrors.errors.txt | 4 +- .../reference/functionOverloads5.errors.txt | 2 +- tests/baselines/reference/i3.errors.txt | 2 +- ...mplementPublicPropertyAsPrivate.errors.txt | 2 +- ...rfaceExtendingClassWithPrivates.errors.txt | 4 +- ...faceExtendingClassWithPrivates2.errors.txt | 16 +- ...andParentPrivateMemberCollision.errors.txt | 2 +- ...MemberCollisionWithPublicMember.errors.txt | 2 +- ...emberCollisionWithPrivateMember.errors.txt | 2 +- ...rfaceExtendingClassWithPrivates.errors.txt | 2 +- ...faceExtendingClassWithPrivates2.errors.txt | 4 +- ...terfaceExtendsClassWithPrivate2.errors.txt | 8 +- .../interfaceImplementation1.errors.txt | 4 +- .../interfaceImplementation6.errors.txt | 2 +- .../interfaceImplementation8.errors.txt | 6 +- ...PropertyThatIsPrivateInBaseType.errors.txt | 4 +- ...ropertyThatIsPrivateInBaseType2.errors.txt | 4 +- ...tionsWithPublicPrivateOverloads.errors.txt | 16 +- ...InterfacesWithInheritedPrivates.errors.txt | 4 +- ...nterfacesWithInheritedPrivates2.errors.txt | 4 +- .../optionalPropertiesTest.errors.txt | 2 +- .../overloadModifiersMustAgree.errors.txt | 2 +- .../overridingPrivateStaticMembers.errors.txt | 2 +- .../reference/parserAstSpans1.errors.txt | 4 +- ...vateInstanceMemberAccessibility.errors.txt | 6 +- .../privateInterfaceProperties.errors.txt | 2 +- ...opertyParameterWithQuestionMark.errors.txt | 2 +- .../reference/protectedMembers.errors.txt | 148 ++++++++++++++ ...lementedAsPrivateInDerivedClass.errors.txt | 2 +- .../baselines/reference/scopeTests.errors.txt | 2 +- .../reference/shadowPrivateMembers.errors.txt | 2 +- ...gWithObjectMembersAccessibility.errors.txt | 6 +- ...WithObjectMembersAccessibility2.errors.txt | 12 +- ...ngWithObjectMembersOptionality2.errors.txt | 6 +- .../reference/superAccess.errors.txt | 4 +- .../reference/superInLambdas.errors.txt | 4 +- .../reference/superPropertyAccess.errors.txt | 10 +- .../reference/superPropertyAccess1.errors.txt | 6 +- .../reference/superPropertyAccess2.errors.txt | 2 +- .../typeIdentityConsidersBrands.errors.txt | 2 +- .../baselines/reference/typeMatch1.errors.txt | 2 +- tests/cases/compiler/protectedMembers.ts | 115 +++++++++++ 68 files changed, 586 insertions(+), 245 deletions(-) create mode 100644 tests/baselines/reference/protectedMembers.errors.txt create mode 100644 tests/cases/compiler/protectedMembers.ts diff --git a/src/compiler/binder.ts b/src/compiler/binder.ts index bae4b6abb3c61..3959335542c68 100644 --- a/src/compiler/binder.ts +++ b/src/compiler/binder.ts @@ -226,7 +226,7 @@ module ts { function bindConstructorDeclaration(node: ConstructorDeclaration) { bindDeclaration(node, SymbolFlags.Constructor, 0); forEach(node.parameters, p => { - if (p.flags & (NodeFlags.Public | NodeFlags.Private)) { + if (p.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)) { bindDeclaration(p, SymbolFlags.Property, SymbolFlags.PropertyExcludes); } }); diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index b99d6d27d20fb..c6d61c7954ae8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -1281,8 +1281,8 @@ module ts { case SyntaxKind.Property: case SyntaxKind.Method: - if (node.flags & NodeFlags.Private) { - // Private properties/methods are not visible + if (node.flags & (NodeFlags.Private | NodeFlags.Protected)) { + // Private/protected properties/methods are not visible return false; } // Public properties/methods are visible if its parents are visible, so let it fall into next case statement @@ -2707,22 +2707,19 @@ module ts { } function isPropertyIdenticalToRecursive(sourceProp: Symbol, targetProp: Symbol, reportErrors: boolean, relate: (source: Type, target: Type, reportErrors: boolean) => boolean): boolean { - Debug.assert(sourceProp); - if (!targetProp) { - return false; - } - // Two members are considered identical when // - they are public properties with identical names, optionality, and types, - // - they are private properties originating in the same declaration and having identical types - var sourcePropIsPrivate = getDeclarationFlagsFromSymbol(sourceProp) & NodeFlags.Private; - var targetPropIsPrivate = getDeclarationFlagsFromSymbol(targetProp) & NodeFlags.Private; - if (sourcePropIsPrivate !== targetPropIsPrivate) { + // - they are private or protected properties originating in the same declaration and having identical types + if (sourceProp === targetProp) { + return true; + } + var sourcePropVisibility = getDeclarationFlagsFromSymbol(sourceProp) & (NodeFlags.Private || NodeFlags.Protected); + var targetPropVisibility = getDeclarationFlagsFromSymbol(targetProp) & (NodeFlags.Private || NodeFlags.Protected); + if (sourcePropVisibility !== targetPropVisibility) { return false; } - - if (sourcePropIsPrivate) { - return (getTargetSymbol(sourceProp).parent === getTargetSymbol(targetProp).parent) && relate(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors); + if (sourcePropVisibility) { + return getTargetSymbol(sourceProp) === getTargetSymbol(targetProp) && relate(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors); } else { return isOptionalProperty(sourceProp) === isOptionalProperty(targetProp) && relate(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors); @@ -2748,8 +2745,8 @@ module ts { } return result; - function reportError(message: DiagnosticMessage, arg0?: string, arg1?: string): void { - errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1); + function reportError(message: DiagnosticMessage, arg0?: string, arg1?: string, arg2?: string): void { + errorInfo = chainDiagnosticMessages(errorInfo, message, arg0, arg1, arg2); } function isRelatedTo(source: Type, target: Type, reportErrors: boolean): boolean { @@ -2921,25 +2918,18 @@ module ts { } function propertiesAreIdenticalTo(source: ObjectType, target: ObjectType, reportErrors: boolean): boolean { - if (source === target) { - return true; - } - var sourceProperties = getPropertiesOfType(source); var targetProperties = getPropertiesOfType(target); if (sourceProperties.length !== targetProperties.length) { return false; } - for (var i = 0, len = sourceProperties.length; i < len; ++i) { var sourceProp = sourceProperties[i]; var targetProp = getPropertyOfType(target, sourceProp.name); - - if (!isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) { + if (!targetProp || !isPropertyIdenticalToRecursive(sourceProp, targetProp, reportErrors, isRelatedTo)) { return false; } } - return true; } @@ -2948,48 +2938,70 @@ module ts { for (var i = 0; i < properties.length; i++) { var targetProp = properties[i]; var sourceProp = getPropertyOfApparentType(source, targetProp.name); - if (sourceProp === targetProp) { - continue; - } - - var targetPropIsOptional = isOptionalProperty(targetProp); - if (!sourceProp) { - if (!targetPropIsOptional) { - if (reportErrors) { - reportError(Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); + if (sourceProp !== targetProp) { + if (!sourceProp) { + if (!isOptionalProperty(targetProp)) { + if (reportErrors) { + reportError(Diagnostics.Property_0_is_missing_in_type_1, symbolToString(targetProp), typeToString(source)); + } + return false; } - return false; - } - } - else if (sourceProp !== targetProp) { - if (targetProp.flags & SymbolFlags.Prototype) { - continue; } - - if (getDeclarationFlagsFromSymbol(sourceProp) & NodeFlags.Private || getDeclarationFlagsFromSymbol(targetProp) & NodeFlags.Private) { - if (reportErrors) { - reportError(Diagnostics.Private_property_0_cannot_be_reimplemented, symbolToString(targetProp)); + else if (!(targetProp.flags & SymbolFlags.Prototype)) { + var sourceFlags = getDeclarationFlagsFromSymbol(sourceProp); + var targetFlags = getDeclarationFlagsFromSymbol(targetProp); + if (sourceFlags & NodeFlags.Private || targetFlags & NodeFlags.Private) { + if (reportErrors) { + if (sourceFlags & NodeFlags.Private && targetFlags & NodeFlags.Private) { + reportError(Diagnostics.Types_have_separate_declarations_of_a_private_property_0, symbolToString(targetProp)); + } + else { + reportError(Diagnostics.Property_0_is_private_in_type_1_but_not_in_type_2, symbolToString(targetProp), + typeToString(sourceFlags & NodeFlags.Private ? source : target), + typeToString(sourceFlags & NodeFlags.Private ? target : source)); + } + } + return false; } - return false; - } - if (!isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors)) { - if (reportErrors) { - reportError(Diagnostics.Types_of_property_0_are_incompatible_Colon, symbolToString(targetProp)); + if (targetFlags & NodeFlags.Protected) { + var sourceDeclaredInClass = sourceProp.parent && sourceProp.parent.flags & SymbolFlags.Class; + var sourceClass = sourceDeclaredInClass ? getDeclaredTypeOfSymbol(sourceProp.parent) : undefined; + var targetClass = getDeclaredTypeOfSymbol(targetProp.parent); + if (!sourceClass || !hasBaseType(sourceClass, targetClass)) { + if (reportErrors) { + reportError(Diagnostics.Property_0_is_protected_but_type_1_is_not_derived_from_type_2, + symbolToString(targetProp), typeToString(sourceClass || source), typeToString(targetClass)); + } + return false; + } } - return false; - } - else if (isOptionalProperty(sourceProp) && !targetPropIsOptional) { - // TypeScript 1.0 spec (April 2014): 3.8.3 - // S is a subtype of a type T, and T is a supertype of S if ... - // S' and T are object types and, for each member M in T.. - // M is a property and S' contains a property N where - // if M is a required property, N is also a required property - // (M - property in T) - // (N - property in S) - if (reportErrors) { - reportError(Diagnostics.Required_property_0_cannot_be_reimplemented_with_optional_property_in_1, targetProp.name, typeToString(source)); + else if (sourceFlags & NodeFlags.Protected) { + if (reportErrors) { + reportError(Diagnostics.Property_0_is_protected_in_type_1_but_public_in_type_2, + symbolToString(targetProp), typeToString(source), typeToString(target)); + } + return false; + } + if (!isRelatedTo(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors)) { + if (reportErrors) { + reportError(Diagnostics.Types_of_property_0_are_incompatible_Colon, symbolToString(targetProp)); + } + return false; + } + if (isOptionalProperty(sourceProp) && !isOptionalProperty(targetProp)) { + // TypeScript 1.0 spec (April 2014): 3.8.3 + // S is a subtype of a type T, and T is a supertype of S if ... + // S' and T are object types and, for each member M in T.. + // M is a property and S' contains a property N where + // if M is a required property, N is also a required property + // (M - property in T) + // (N - property in S) + if (reportErrors) { + reportError(Diagnostics.Property_0_is_optional_in_type_1_but_required_in_type_2, + symbolToString(targetProp), typeToString(source), typeToString(target)); + } + return false; } - return false; } } } @@ -3997,6 +4009,31 @@ module ts { return s.valueDeclaration ? s.valueDeclaration.flags : s.flags & SymbolFlags.Prototype ? NodeFlags.Public | NodeFlags.Static : 0; } + function isClassPropertyAccessible(node: PropertyAccess, type: Type, prop: Symbol): boolean { + var flags = getDeclarationFlagsFromSymbol(prop); + if (!(flags & (NodeFlags.Private | NodeFlags.Protected))) { + return true; + } + var enclosingClassDeclaration = getAncestor(node, SyntaxKind.ClassDeclaration); + if (!enclosingClassDeclaration) { + return false; + } + var declaringClass = getDeclaredTypeOfSymbol(prop.parent); + var enclosingClass = getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)); + if (flags & NodeFlags.Private) { + return declaringClass === enclosingClass; + } + if (node.left.kind === SyntaxKind.SuperKeyword) { + return true; + } + if (!(flags & NodeFlags.Static)) { + if (!(getTargetType(type).flags & (TypeFlags.Class | TypeFlags.Interface) && hasBaseType(type, enclosingClass))) { + return false; + } + } + return hasBaseType(enclosingClass, declaringClass); + } + function checkPropertyAccess(node: PropertyAccess) { var type = checkExpression(node.left); if (type === unknownType) return type; @@ -4015,7 +4052,6 @@ module ts { } getNodeLinks(node).resolvedSymbol = prop; if (prop.parent && prop.parent.flags & SymbolFlags.Class) { - // TS 1.0 spec (April 2014): 4.8.2 // - In a constructor, instance member function, instance member accessor, or // instance member variable initializer where this references a derived class instance, @@ -4024,13 +4060,10 @@ module ts { // 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 (node.left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.Method) { - error(node.right, Diagnostics.Only_public_methods_of_the_base_class_are_accessible_via_the_super_keyword); + error(node.right, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); } - else if (getDeclarationFlagsFromSymbol(prop) & NodeFlags.Private) { - var classDeclaration = getAncestor(node, SyntaxKind.ClassDeclaration); - if (!classDeclaration || !contains(prop.parent.declarations, classDeclaration)) { - error(node, Diagnostics.Property_0_is_inaccessible, getFullyQualifiedName(prop)); - } + else if (!isClassPropertyAccessible(node, type, prop)) { + error(node, Diagnostics.Property_0_is_inaccessible, getFullyQualifiedName(prop)); } } return getTypeOfSymbol(prop); @@ -4986,7 +5019,8 @@ module ts { if (fullTypeCheck) { checkCollisionWithIndexVariableInGeneratedCode(parameterDeclaration, parameterDeclaration.name); - if (parameterDeclaration.flags & (NodeFlags.Public | NodeFlags.Private) && !(parameterDeclaration.parent.kind === SyntaxKind.Constructor && (parameterDeclaration.parent).body)) { + if (parameterDeclaration.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected) && + !(parameterDeclaration.parent.kind === SyntaxKind.Constructor && (parameterDeclaration.parent).body)) { error(parameterDeclaration, Diagnostics.A_parameter_property_is_only_allowed_in_a_constructor_implementation); } if (parameterDeclaration.flags & NodeFlags.Rest) { @@ -5179,7 +5213,7 @@ module ts { // or the containing class declares instance member variables with initializers. var superCallShouldBeFirst = forEach((node.parent).members, isInstancePropertyWithInitializer) || - forEach(node.parameters, p => p.flags & (NodeFlags.Public | NodeFlags.Private)); + forEach(node.parameters, p => p.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)); if (superCallShouldBeFirst) { var statements = (node.body).statements; @@ -5211,7 +5245,7 @@ module ts { var otherKind = node.kind === SyntaxKind.GetAccessor ? SyntaxKind.SetAccessor : SyntaxKind.GetAccessor; var otherAccessor = getDeclarationOfKind(node.symbol, otherKind); if (otherAccessor) { - var visibilityFlags = NodeFlags.Private | NodeFlags.Public; + var visibilityFlags = NodeFlags.Private | NodeFlags.Public | NodeFlags.Protected; if (((node.flags & visibilityFlags) !== (otherAccessor.flags & visibilityFlags))) { error(node.name, Diagnostics.Getter_and_setter_accessors_do_not_agree_in_visibility); } @@ -5357,8 +5391,8 @@ module ts { else if (deviation & NodeFlags.Ambient) { error(o.name, Diagnostics.Overload_signatures_must_all_be_ambient_or_non_ambient); } - else if (deviation & NodeFlags.Private) { - error(o.name, Diagnostics.Overload_signatures_must_all_be_public_or_private); + else if (deviation & (NodeFlags.Private | NodeFlags.Protected)) { + error(o.name, Diagnostics.Overload_signatures_must_all_be_public_private_or_protected); } else if (deviation & NodeFlags.QuestionMark) { error(o.name, Diagnostics.Overload_signatures_must_all_be_optional_or_required); @@ -5367,7 +5401,7 @@ module ts { } } - var flagsToCheck: NodeFlags = NodeFlags.Export | NodeFlags.Ambient | NodeFlags.Private | NodeFlags.QuestionMark; + var flagsToCheck: NodeFlags = NodeFlags.Export | NodeFlags.Ambient | NodeFlags.Private | NodeFlags.Protected | NodeFlags.QuestionMark; var someNodeFlags: NodeFlags = 0; var allNodeFlags = flagsToCheck; var hasOverloads = false; @@ -6147,7 +6181,7 @@ module ts { } function getTargetSymbol(s: Symbol) { - // if symbol is instantiated it's flags are not copied from the 'target' + // if symbol is instantiated its flags are not copied from the 'target' // so we'll need to get back original 'target' symbol to work with correct set of flags return s.flags & SymbolFlags.Instantiated ? getSymbolLinks(s).target : s; } diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 04dbafc254e84..772a386af2c22 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -138,9 +138,9 @@ module ts { Type_0_is_not_assignable_to_type_1_Colon: { code: 2322, category: DiagnosticCategory.Error, key: "Type '{0}' is not assignable to type '{1}':" }, Type_0_is_not_assignable_to_type_1: { code: 2323, category: DiagnosticCategory.Error, key: "Type '{0}' is not assignable to type '{1}'." }, Property_0_is_missing_in_type_1: { code: 2324, category: DiagnosticCategory.Error, key: "Property '{0}' is missing in type '{1}'." }, - Private_property_0_cannot_be_reimplemented: { code: 2325, category: DiagnosticCategory.Error, key: "Private property '{0}' cannot be reimplemented." }, + Property_0_is_private_in_type_1_but_not_in_type_2: { code: 2325, category: DiagnosticCategory.Error, key: "Property '{0}' is private in type '{1}' but not in type '{2}'." }, Types_of_property_0_are_incompatible_Colon: { code: 2326, category: DiagnosticCategory.Error, key: "Types of property '{0}' are incompatible:" }, - Required_property_0_cannot_be_reimplemented_with_optional_property_in_1: { code: 2327, category: DiagnosticCategory.Error, key: "Required property '{0}' cannot be reimplemented with optional property in '{1}'." }, + Property_0_is_optional_in_type_1_but_required_in_type_2: { code: 2327, category: DiagnosticCategory.Error, key: "Property '{0}' is optional in type '{1}' but required in type '{2}'." }, Types_of_parameters_0_and_1_are_incompatible_Colon: { code: 2328, category: DiagnosticCategory.Error, key: "Types of parameters '{0}' and '{1}' are incompatible:" }, Index_signature_is_missing_in_type_0: { code: 2329, category: DiagnosticCategory.Error, key: "Index signature is missing in type '{0}'." }, Index_signatures_are_incompatible_Colon: { code: 2330, category: DiagnosticCategory.Error, key: "Index signatures are incompatible:" }, @@ -153,7 +153,7 @@ module ts { Super_calls_are_not_permitted_outside_constructors_or_in_nested_functions_inside_constructors: { code: 2337, category: DiagnosticCategory.Error, key: "Super calls are not permitted outside constructors or in nested functions inside constructors" }, super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class: { code: 2338, category: DiagnosticCategory.Error, key: "'super' property access is permitted only in a constructor, member function, or member accessor of a derived class" }, Property_0_does_not_exist_on_type_1: { code: 2339, category: DiagnosticCategory.Error, key: "Property '{0}' does not exist on type '{1}'." }, - Only_public_methods_of_the_base_class_are_accessible_via_the_super_keyword: { code: 2340, category: DiagnosticCategory.Error, key: "Only public methods of the base class are accessible via the 'super' keyword" }, + Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword: { code: 2340, category: DiagnosticCategory.Error, key: "Only public and protected methods of the base class are accessible via the 'super' keyword" }, Property_0_is_inaccessible: { code: 2341, category: DiagnosticCategory.Error, key: "Property '{0}' is inaccessible." }, An_index_expression_argument_must_be_of_type_string_number_or_any: { code: 2342, category: DiagnosticCategory.Error, key: "An index expression argument must be of type 'string', 'number', or 'any'." }, Type_0_does_not_satisfy_the_constraint_1_Colon: { code: 2343, category: DiagnosticCategory.Error, key: "Type '{0}' does not satisfy the constraint '{1}':" }, @@ -198,7 +198,7 @@ module ts { Specialized_overload_signature_is_not_assignable_to_any_non_specialized_signature: { code: 2382, category: DiagnosticCategory.Error, key: "Specialized overload signature is not assignable to any non-specialized signature." }, Overload_signatures_must_all_be_exported_or_not_exported: { code: 2383, category: DiagnosticCategory.Error, key: "Overload signatures must all be exported or not exported." }, Overload_signatures_must_all_be_ambient_or_non_ambient: { code: 2384, category: DiagnosticCategory.Error, key: "Overload signatures must all be ambient or non-ambient." }, - Overload_signatures_must_all_be_public_or_private: { code: 2385, category: DiagnosticCategory.Error, key: "Overload signatures must all be public or private." }, + Overload_signatures_must_all_be_public_private_or_protected: { code: 2385, category: DiagnosticCategory.Error, key: "Overload signatures must all be public, private or protected." }, Overload_signatures_must_all_be_optional_or_required: { code: 2386, category: DiagnosticCategory.Error, key: "Overload signatures must all be optional or required." }, Function_overload_must_be_static: { code: 2387, category: DiagnosticCategory.Error, key: "Function overload must be static." }, Function_overload_must_not_be_static: { code: 2388, category: DiagnosticCategory.Error, key: "Function overload must not be static." }, @@ -255,6 +255,9 @@ module ts { Import_declaration_in_an_ambient_external_module_declaration_cannot_reference_external_module_through_relative_external_module_name: { code: 2439, category: DiagnosticCategory.Error, key: "Import declaration in an ambient external module declaration cannot reference external module through relative external module name." }, Import_declaration_conflicts_with_local_declaration_of_0: { code: 2440, category: DiagnosticCategory.Error, key: "Import declaration conflicts with local declaration of '{0}'" }, Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module: { code: 2441, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler reserves name '{1}' in top level scope of an external module." }, + Types_have_separate_declarations_of_a_private_property_0: { code: 2442, category: DiagnosticCategory.Error, key: "Types have separate declarations of a private property '{0}'." }, + Property_0_is_protected_but_type_1_is_not_derived_from_type_2: { code: 2443, category: DiagnosticCategory.Error, key: "Property '{0}' is protected but type '{1}' is not derived from type '{2}'." }, + Property_0_is_protected_in_type_1_but_public_in_type_2: { code: 2444, category: DiagnosticCategory.Error, key: "Property '{0}' is protected in type '{1}' but public in type '{2}'." }, 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_name_1_from_private_module_2: { code: 4001, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, 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}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 6c78ec6bd5db9..2e4ed8ce7a983 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -544,7 +544,7 @@ "category": "Error", "code": 2324 }, - "Private property '{0}' cannot be reimplemented.": { + "Property '{0}' is private in type '{1}' but not in type '{2}'.": { "category": "Error", "code": 2325 }, @@ -552,7 +552,7 @@ "category": "Error", "code": 2326 }, - "Required property '{0}' cannot be reimplemented with optional property in '{1}'.": { + "Property '{0}' is optional in type '{1}' but required in type '{2}'.": { "category": "Error", "code": 2327 }, @@ -604,7 +604,7 @@ "category": "Error", "code": 2339 }, - "Only public methods of the base class are accessible via the 'super' keyword": { + "Only public and protected methods of the base class are accessible via the 'super' keyword": { "category": "Error", "code": 2340 }, @@ -784,7 +784,7 @@ "category": "Error", "code": 2384 }, - "Overload signatures must all be public or private.": { + "Overload signatures must all be public, private or protected.": { "category": "Error", "code": 2385 }, @@ -1012,7 +1012,18 @@ "category": "Error", "code": 2441 }, - + "Types have separate declarations of a private property '{0}'.": { + "category": "Error", + "code": 2442 + }, + "Property '{0}' is protected but type '{1}' is not derived from type '{2}'.": { + "category": "Error", + "code": 2443 + }, + "Property '{0}' is protected in type '{1}' but public in type '{2}'.": { + "category": "Error", + "code": 2444 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", diff --git a/src/compiler/emitter.ts b/src/compiler/emitter.ts index 317db201f3e81..51dcc07a3c0b0 100644 --- a/src/compiler/emitter.ts +++ b/src/compiler/emitter.ts @@ -1431,7 +1431,7 @@ module ts { function emitParameterPropertyAssignments(node: ConstructorDeclaration) { forEach(node.parameters, param => { - if (param.flags & (NodeFlags.Public | NodeFlags.Private)) { + if (param.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)) { writeLine(); emitStart(param); emitStart(param.name); @@ -2368,12 +2368,18 @@ module ts { if (node.flags & NodeFlags.Private) { write("private "); } + else if (node.flags & NodeFlags.Protected) { + write("protected "); + } write("static "); } else { if (node.flags & NodeFlags.Private) { write("private "); } + else if (node.flags & NodeFlags.Protected) { + write("protected "); + } // If the node is parented in the current source file we need to emit export declare or just export else if (node.parent === currentSourceFile) { // If the node is exported @@ -2630,7 +2636,7 @@ module ts { function emitParameterProperties(constructorDeclaration: ConstructorDeclaration) { if (constructorDeclaration) { forEach(constructorDeclaration.parameters, param => { - if (param.flags & (NodeFlags.Public | NodeFlags.Private)) { + if (param.flags & (NodeFlags.Public | NodeFlags.Private | NodeFlags.Protected)) { emitPropertyDeclaration(param); } }); diff --git a/src/compiler/parser.ts b/src/compiler/parser.ts index 25ca24ae61b66..da0d7b658f50c 100644 --- a/src/compiler/parser.ts +++ b/src/compiler/parser.ts @@ -597,6 +597,7 @@ module ts { switch (token) { case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: case SyntaxKind.StaticKeyword: case SyntaxKind.ExportKeyword: case SyntaxKind.DeclareKeyword: @@ -2883,6 +2884,7 @@ module ts { } case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: case SyntaxKind.StaticKeyword: // When followed by an identifier or keyword, these do not start a statement but // might instead be following type members @@ -3201,6 +3203,8 @@ module ts { var lastDeclareModifierLength: number; var lastPrivateModifierStart: number; var lastPrivateModifierLength: number; + var lastProtectedModifierStart: number; + var lastProtectedModifierLength: number; while (true) { var modifierStart = scanner.getTokenPos(); @@ -3213,7 +3217,7 @@ module ts { switch (modifierToken) { case SyntaxKind.PublicKeyword: - if (flags & NodeFlags.Private || flags & NodeFlags.Public) { + if (flags & NodeFlags.Public || flags & NodeFlags.Private || flags & NodeFlags.Protected) { grammarErrorAtPos(modifierStart, modifierLength, Diagnostics.Accessibility_modifier_already_seen); } else if (flags & NodeFlags.Static) { @@ -3226,7 +3230,7 @@ module ts { break; case SyntaxKind.PrivateKeyword: - if (flags & NodeFlags.Private || flags & NodeFlags.Public) { + if (flags & NodeFlags.Public || flags & NodeFlags.Private || flags & NodeFlags.Protected) { grammarErrorAtPos(modifierStart, modifierLength, Diagnostics.Accessibility_modifier_already_seen); } else if (flags & NodeFlags.Static) { @@ -3240,6 +3244,21 @@ module ts { flags |= NodeFlags.Private; break; + case SyntaxKind.ProtectedKeyword: + if (flags & NodeFlags.Public || flags & NodeFlags.Private || flags & NodeFlags.Protected) { + grammarErrorAtPos(modifierStart, modifierLength, Diagnostics.Accessibility_modifier_already_seen); + } + else if (flags & NodeFlags.Static) { + grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_must_precede_1_modifier, "protected", "static"); + } + else if (context === ModifierContext.ModuleElements || context === ModifierContext.SourceElements) { + grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_cannot_appear_on_a_module_element, "protected"); + } + lastProtectedModifierStart = modifierStart; + lastProtectedModifierLength = modifierLength; + flags |= NodeFlags.Protected; + break; + case SyntaxKind.StaticKeyword: if (flags & NodeFlags.Static) { grammarErrorAtPos(modifierStart, modifierLength, Diagnostics._0_modifier_already_seen, "static"); @@ -3297,6 +3316,9 @@ module ts { else if (token === SyntaxKind.ConstructorKeyword && flags & NodeFlags.Private) { grammarErrorAtPos(lastPrivateModifierStart, lastPrivateModifierLength, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "private"); } + else if (token === SyntaxKind.ConstructorKeyword && flags & NodeFlags.Protected) { + grammarErrorAtPos(lastProtectedModifierStart, lastProtectedModifierLength, Diagnostics._0_modifier_cannot_appear_on_a_constructor_declaration, "protected"); + } else if (token === SyntaxKind.ImportKeyword) { if (flags & NodeFlags.Ambient) { grammarErrorAtPos(lastDeclareModifierStart, lastDeclareModifierLength, Diagnostics.A_declare_modifier_cannot_be_used_with_an_import_declaration, "declare"); @@ -3573,6 +3595,7 @@ module ts { case SyntaxKind.DeclareKeyword: case SyntaxKind.PublicKeyword: case SyntaxKind.PrivateKeyword: + case SyntaxKind.ProtectedKeyword: case SyntaxKind.StaticKeyword: // Check for modifier on source element return lookAhead(() => { nextToken(); return isDeclaration(); }); diff --git a/src/compiler/types.ts b/src/compiler/types.ts index bb8a106a81321..5bf7c9251618b 100644 --- a/src/compiler/types.ts +++ b/src/compiler/types.ts @@ -232,12 +232,13 @@ module ts { Rest = 0x00000008, // Parameter Public = 0x00000010, // Property/Method Private = 0x00000020, // Property/Method - Static = 0x00000040, // Property/Method - MultiLine = 0x00000080, // Multi-line array or object literal - Synthetic = 0x00000100, // Synthetic node (for full fidelity) - DeclarationFile = 0x00000200, // Node is a .d.ts file + Protected = 0x00000040, // Property/Method + Static = 0x00000080, // Property/Method + MultiLine = 0x00000100, // Multi-line array or object literal + Synthetic = 0x00000200, // Synthetic node (for full fidelity) + DeclarationFile = 0x00000400, // Node is a .d.ts file - Modifier = Export | Ambient | Public | Private | Static + Modifier = Export | Ambient | Public | Private | Protected | Static } export interface Node extends TextRange { diff --git a/tests/baselines/reference/assignmentCompatWithObjectMembersAccessibility.errors.txt b/tests/baselines/reference/assignmentCompatWithObjectMembersAccessibility.errors.txt index 75ba383671c0d..1cf5cc6f118c8 100644 --- a/tests/baselines/reference/assignmentCompatWithObjectMembersAccessibility.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithObjectMembersAccessibility.errors.txt @@ -32,7 +32,7 @@ a = e; // error ~ !!! Type 'E' is not assignable to type '{ foo: string; }': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'E' but not in type '{ foo: string; }'. b = a; b = i; @@ -40,7 +40,7 @@ b = e; // error ~ !!! Type 'E' is not assignable to type 'Base': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'E' but not in type 'Base'. i = a; i = b; @@ -48,7 +48,7 @@ i = e; // error ~ !!! Type 'E' is not assignable to type 'I': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'E' but not in type 'I'. d = a; d = b; @@ -56,24 +56,24 @@ d = e; // error ~ !!! Type 'E' is not assignable to type 'D': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'E' but not in type 'D'. e = a; // errror ~ !!! Type '{ foo: string; }' is not assignable to type 'E': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'E' but not in type '{ foo: string; }'. e = b; // errror ~ !!! Type 'Base' is not assignable to type 'E': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'E' but not in type 'Base'. e = i; // errror ~ !!! Type 'I' is not assignable to type 'E': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'E' but not in type 'I'. e = d; // errror ~ !!! Type 'D' is not assignable to type 'E': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'E' but not in type 'D'. e = e; } @@ -106,77 +106,77 @@ a = b; // error ~ !!! Type 'Base' is not assignable to type '{ foo: string; }': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'Base' but not in type '{ foo: string; }'. a = i; // error ~ !!! Type 'I' is not assignable to type '{ foo: string; }': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'I' but not in type '{ foo: string; }'. a = d; a = e; // error ~ !!! Type 'E' is not assignable to type '{ foo: string; }': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'E' but not in type '{ foo: string; }'. b = a; // error ~ !!! Type '{ foo: string; }' is not assignable to type 'Base': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'Base' but not in type '{ foo: string; }'. b = i; b = d; // error ~ !!! Type 'D' is not assignable to type 'Base': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'Base' but not in type 'D'. b = e; // error ~ !!! Type 'E' is not assignable to type 'Base': -!!! Private property 'foo' cannot be reimplemented. +!!! Types have separate declarations of a private property 'foo'. b = b; i = a; // error ~ !!! Type '{ foo: string; }' is not assignable to type 'I': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'I' but not in type '{ foo: string; }'. i = b; i = d; // error ~ !!! Type 'D' is not assignable to type 'I': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'I' but not in type 'D'. i = e; // error ~ !!! Type 'E' is not assignable to type 'I': -!!! Private property 'foo' cannot be reimplemented. +!!! Types have separate declarations of a private property 'foo'. i = i; d = a; d = b; // error ~ !!! Type 'Base' is not assignable to type 'D': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'Base' but not in type 'D'. d = i; // error ~ !!! Type 'I' is not assignable to type 'D': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'I' but not in type 'D'. d = e; // error ~ !!! Type 'E' is not assignable to type 'D': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'E' but not in type 'D'. e = a; // errror ~ !!! Type '{ foo: string; }' is not assignable to type 'E': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'E' but not in type '{ foo: string; }'. e = b; // errror ~ !!! Type 'Base' is not assignable to type 'E': -!!! Private property 'foo' cannot be reimplemented. +!!! Types have separate declarations of a private property 'foo'. e = i; // errror ~ !!! Type 'I' is not assignable to type 'E': -!!! Private property 'foo' cannot be reimplemented. +!!! Types have separate declarations of a private property 'foo'. e = d; // errror ~ !!! Type 'D' is not assignable to type 'E': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'E' but not in type 'D'. e = e; } \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatWithObjectMembersOptionality.errors.txt b/tests/baselines/reference/assignmentCompatWithObjectMembersOptionality.errors.txt index 1e2b287f9420a..eb11a3433d408 100644 --- a/tests/baselines/reference/assignmentCompatWithObjectMembersOptionality.errors.txt +++ b/tests/baselines/reference/assignmentCompatWithObjectMembersOptionality.errors.txt @@ -74,33 +74,33 @@ c = d; // error ~ !!! Type 'D' is not assignable to type 'C': -!!! Required property 'opt' cannot be reimplemented with optional property in 'D'. +!!! Property 'opt' is optional in type 'D' but required in type 'C'. c = e; // error ~ !!! Type 'E' is not assignable to type 'C': -!!! Required property 'opt' cannot be reimplemented with optional property in 'E'. +!!! Property 'opt' is optional in type 'E' but required in type 'C'. c = f; // ok c = a; // ok a = d; // error ~ !!! Type 'D' is not assignable to type '{ opt: Base; }': -!!! Required property 'opt' cannot be reimplemented with optional property in 'D'. +!!! Property 'opt' is optional in type 'D' but required in type '{ opt: Base; }'. a = e; // error ~ !!! Type 'E' is not assignable to type '{ opt: Base; }': -!!! Required property 'opt' cannot be reimplemented with optional property in 'E'. +!!! Property 'opt' is optional in type 'E' but required in type '{ opt: Base; }'. a = f; // ok a = c; // ok b = d; // error ~ !!! Type 'D' is not assignable to type '{ opt: Base; }': -!!! Required property 'opt' cannot be reimplemented with optional property in 'D'. +!!! Property 'opt' is optional in type 'D' but required in type '{ opt: Base; }'. b = e; // error ~ !!! Type 'E' is not assignable to type '{ opt: Base; }': -!!! Required property 'opt' cannot be reimplemented with optional property in 'E'. +!!! Property 'opt' is optional in type 'E' but required in type '{ opt: Base; }'. b = f; // ok b = a; // ok b = c; // ok diff --git a/tests/baselines/reference/assignmentCompatability10.errors.txt b/tests/baselines/reference/assignmentCompatability10.errors.txt index 25f76e83c07af..6e2baaeebee02 100644 --- a/tests/baselines/reference/assignmentCompatability10.errors.txt +++ b/tests/baselines/reference/assignmentCompatability10.errors.txt @@ -10,4 +10,4 @@ __test2__.__val__x4 = __test1__.__val__obj4 ~~~~~~~~~~~~~~~~~~~ !!! Type 'interfaceWithPublicAndOptional' is not assignable to type 'classWithPublicAndOptional': -!!! Required property 'two' cannot be reimplemented with optional property in 'interfaceWithPublicAndOptional'. \ No newline at end of file +!!! Property 'two' is optional in type 'interfaceWithPublicAndOptional' but required in type 'classWithPublicAndOptional'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability13.errors.txt b/tests/baselines/reference/assignmentCompatability13.errors.txt index 5cdfab0b13cc8..7c8af8b2994f1 100644 --- a/tests/baselines/reference/assignmentCompatability13.errors.txt +++ b/tests/baselines/reference/assignmentCompatability13.errors.txt @@ -10,4 +10,4 @@ __test2__.__val__obj = __test1__.__val__obj4 ~~~~~~~~~~~~~~~~~~~~ !!! Type 'interfaceWithPublicAndOptional' is not assignable to type '{ two: string; }': -!!! Required property 'two' cannot be reimplemented with optional property in 'interfaceWithPublicAndOptional'. \ No newline at end of file +!!! Property 'two' is optional in type 'interfaceWithPublicAndOptional' but required in type '{ two: string; }'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability27.errors.txt b/tests/baselines/reference/assignmentCompatability27.errors.txt index 26948fe97eabe..36339c4433e0c 100644 --- a/tests/baselines/reference/assignmentCompatability27.errors.txt +++ b/tests/baselines/reference/assignmentCompatability27.errors.txt @@ -10,4 +10,4 @@ __test2__.__val__aa = __test1__.__val__obj4 ~~~~~~~~~~~~~~~~~~~ !!! Type 'interfaceWithPublicAndOptional' is not assignable to type '{ two: string; }': -!!! Required property 'two' cannot be reimplemented with optional property in 'interfaceWithPublicAndOptional'. \ No newline at end of file +!!! Property 'two' is optional in type 'interfaceWithPublicAndOptional' but required in type '{ two: string; }'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability39.errors.txt b/tests/baselines/reference/assignmentCompatability39.errors.txt index f924512d461b7..ebfdd74cc40c6 100644 --- a/tests/baselines/reference/assignmentCompatability39.errors.txt +++ b/tests/baselines/reference/assignmentCompatability39.errors.txt @@ -10,4 +10,4 @@ __test2__.__val__x2 = __test1__.__val__obj4 ~~~~~~~~~~~~~~~~~~~ !!! Type 'interfaceWithPublicAndOptional' is not assignable to type 'classWithTwoPublic': -!!! Required property 'two' cannot be reimplemented with optional property in 'interfaceWithPublicAndOptional'. \ No newline at end of file +!!! Property 'two' is optional in type 'interfaceWithPublicAndOptional' but required in type 'classWithTwoPublic'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability40.errors.txt b/tests/baselines/reference/assignmentCompatability40.errors.txt index db1948d7cb06f..373475cc9c883 100644 --- a/tests/baselines/reference/assignmentCompatability40.errors.txt +++ b/tests/baselines/reference/assignmentCompatability40.errors.txt @@ -10,4 +10,4 @@ __test2__.__val__x5 = __test1__.__val__obj4 ~~~~~~~~~~~~~~~~~~~ !!! Type 'interfaceWithPublicAndOptional' is not assignable to type 'classWithPrivate': -!!! Private property 'one' cannot be reimplemented. \ No newline at end of file +!!! Property 'one' is private in type 'classWithPrivate' but not in type 'interfaceWithPublicAndOptional'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability41.errors.txt b/tests/baselines/reference/assignmentCompatability41.errors.txt index e21dc1c8cd329..138e3f9104efb 100644 --- a/tests/baselines/reference/assignmentCompatability41.errors.txt +++ b/tests/baselines/reference/assignmentCompatability41.errors.txt @@ -10,4 +10,4 @@ __test2__.__val__x6 = __test1__.__val__obj4 ~~~~~~~~~~~~~~~~~~~ !!! Type 'interfaceWithPublicAndOptional' is not assignable to type 'classWithTwoPrivate': -!!! Private property 'one' cannot be reimplemented. \ No newline at end of file +!!! Property 'one' is private in type 'classWithTwoPrivate' but not in type 'interfaceWithPublicAndOptional'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability42.errors.txt b/tests/baselines/reference/assignmentCompatability42.errors.txt index 2258a85139edb..53afa92ea4a10 100644 --- a/tests/baselines/reference/assignmentCompatability42.errors.txt +++ b/tests/baselines/reference/assignmentCompatability42.errors.txt @@ -10,4 +10,4 @@ __test2__.__val__x7 = __test1__.__val__obj4 ~~~~~~~~~~~~~~~~~~~ !!! Type 'interfaceWithPublicAndOptional' is not assignable to type 'classWithPublicPrivate': -!!! Private property 'two' cannot be reimplemented. \ No newline at end of file +!!! Property 'two' is private in type 'classWithPublicPrivate' but not in type 'interfaceWithPublicAndOptional'. \ No newline at end of file diff --git a/tests/baselines/reference/assignmentCompatability43.errors.txt b/tests/baselines/reference/assignmentCompatability43.errors.txt index 1ab4e3dcef8e2..4ea0ce3025047 100644 --- a/tests/baselines/reference/assignmentCompatability43.errors.txt +++ b/tests/baselines/reference/assignmentCompatability43.errors.txt @@ -10,4 +10,4 @@ __test2__.__val__obj2 = __test1__.__val__obj4 ~~~~~~~~~~~~~~~~~~~~~ !!! Type 'interfaceWithPublicAndOptional' is not assignable to type 'interfaceTwo': -!!! Required property 'two' cannot be reimplemented with optional property in 'interfaceWithPublicAndOptional'. \ No newline at end of file +!!! Property 'two' is optional in type 'interfaceWithPublicAndOptional' but required in type 'interfaceTwo'. \ No newline at end of file diff --git a/tests/baselines/reference/classExtendsInterfaceThatExtendsClassWithPrivates1.errors.txt b/tests/baselines/reference/classExtendsInterfaceThatExtendsClassWithPrivates1.errors.txt index a74abc33755be..b7dac5e5f2a45 100644 --- a/tests/baselines/reference/classExtendsInterfaceThatExtendsClassWithPrivates1.errors.txt +++ b/tests/baselines/reference/classExtendsInterfaceThatExtendsClassWithPrivates1.errors.txt @@ -11,7 +11,7 @@ class D2 implements I { ~~ !!! Class 'D2' incorrectly implements interface 'I': -!!! Private property 'x' cannot be reimplemented. +!!! Types have separate declarations of a private property 'x'. public foo(x: any) { return x } private x = 3; other(x: any) { return x } diff --git a/tests/baselines/reference/classImplementsClass5.errors.txt b/tests/baselines/reference/classImplementsClass5.errors.txt index 97f83fc83f886..c346da94f067d 100644 --- a/tests/baselines/reference/classImplementsClass5.errors.txt +++ b/tests/baselines/reference/classImplementsClass5.errors.txt @@ -6,7 +6,7 @@ class C implements A { ~ !!! Class 'C' incorrectly implements interface 'A': -!!! Private property 'x' cannot be reimplemented. +!!! Types have separate declarations of a private property 'x'. private x = 1; foo() { return 1; @@ -20,8 +20,8 @@ c = c2; ~ !!! Type 'C2' is not assignable to type 'C': -!!! Private property 'x' cannot be reimplemented. +!!! Types have separate declarations of a private property 'x'. c2 = c; ~~ !!! Type 'C' is not assignable to type 'C2': -!!! Private property 'x' cannot be reimplemented. \ No newline at end of file +!!! Types have separate declarations of a private property 'x'. \ No newline at end of file diff --git a/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt b/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt index fa5dcab097351..7f61ec0a25889 100644 --- a/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt +++ b/tests/baselines/reference/classIsSubtypeOfBaseType.errors.txt @@ -14,7 +14,7 @@ !!! Class 'Derived2' incorrectly extends base class 'Base<{ bar: string; }>': !!! Types of property 'foo' are incompatible: !!! Type '{ bar?: string; }' is not assignable to type '{ bar: string; }': -!!! Required property 'bar' cannot be reimplemented with optional property in '{ bar?: string; }'. +!!! Property 'bar' is optional in type '{ bar?: string; }' but required in type '{ bar: string; }'. foo: { bar?: string; // error } diff --git a/tests/baselines/reference/classUpdateTests.errors.txt b/tests/baselines/reference/classUpdateTests.errors.txt index f7f4036254b6b..237195b5a9d2f 100644 --- a/tests/baselines/reference/classUpdateTests.errors.txt +++ b/tests/baselines/reference/classUpdateTests.errors.txt @@ -77,7 +77,7 @@ class L extends G { ~ !!! Class 'L' incorrectly extends base class 'G': -!!! Private property 'p1' cannot be reimplemented. +!!! Property 'p1' is private in type 'L' but not in type 'G'. constructor(private p1:number) { super(); // NO ERROR } @@ -86,7 +86,7 @@ class M extends G { ~ !!! Class 'M' incorrectly extends base class 'G': -!!! Private property 'p1' cannot be reimplemented. +!!! Property 'p1' is private in type 'M' but not in type 'G'. constructor(private p1:number) { // ERROR ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ var i = 0; diff --git a/tests/baselines/reference/derivedClassOverridesPrivateFunction1.errors.txt b/tests/baselines/reference/derivedClassOverridesPrivateFunction1.errors.txt index 3eb2f197ca0f0..1465629770006 100644 --- a/tests/baselines/reference/derivedClassOverridesPrivateFunction1.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesPrivateFunction1.errors.txt @@ -9,7 +9,7 @@ class DerivedClass extends BaseClass { ~~~~~~~~~~~~ !!! Class 'DerivedClass' incorrectly extends base class 'BaseClass': -!!! Private property '_init' cannot be reimplemented. +!!! Types have separate declarations of a private property '_init'. constructor() { super(); } diff --git a/tests/baselines/reference/derivedClassOverridesPrivates.errors.txt b/tests/baselines/reference/derivedClassOverridesPrivates.errors.txt index c6d8f2305893d..28db24606f424 100644 --- a/tests/baselines/reference/derivedClassOverridesPrivates.errors.txt +++ b/tests/baselines/reference/derivedClassOverridesPrivates.errors.txt @@ -6,7 +6,7 @@ class Derived extends Base { ~~~~~~~ !!! Class 'Derived' incorrectly extends base class 'Base': -!!! Private property 'x' cannot be reimplemented. +!!! Types have separate declarations of a private property 'x'. private x: { foo: string; bar: string; }; // error } @@ -17,6 +17,6 @@ class Derived2 extends Base2 { ~~~~~~~~ !!! Class static side 'typeof Derived2' incorrectly extends base class static side 'typeof Base2': -!!! Private property 'y' cannot be reimplemented. +!!! Types have separate declarations of a private property 'y'. private static y: { foo: string; bar: string; }; // error } \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassWithPrivateInstanceShadowingPublicInstance.errors.txt b/tests/baselines/reference/derivedClassWithPrivateInstanceShadowingPublicInstance.errors.txt index c467c5530969f..4a3e11aca3c75 100644 --- a/tests/baselines/reference/derivedClassWithPrivateInstanceShadowingPublicInstance.errors.txt +++ b/tests/baselines/reference/derivedClassWithPrivateInstanceShadowingPublicInstance.errors.txt @@ -17,7 +17,7 @@ class Derived extends Base { ~~~~~~~ !!! Class 'Derived' incorrectly extends base class 'Base': -!!! Private property 'x' cannot be reimplemented. +!!! Property 'x' is private in type 'Derived' but not in type 'Base'. private x: string; private fn(): string { return ''; diff --git a/tests/baselines/reference/derivedClassWithPrivateStaticShadowingPublicStatic.errors.txt b/tests/baselines/reference/derivedClassWithPrivateStaticShadowingPublicStatic.errors.txt index 9d5ee12954177..86aa87a664abd 100644 --- a/tests/baselines/reference/derivedClassWithPrivateStaticShadowingPublicStatic.errors.txt +++ b/tests/baselines/reference/derivedClassWithPrivateStaticShadowingPublicStatic.errors.txt @@ -18,7 +18,7 @@ class Derived extends Base { ~~~~~~~ !!! Class static side 'typeof Derived' incorrectly extends base class static side 'typeof Base': -!!! Private property 'x' cannot be reimplemented. +!!! Property 'x' is private in type 'typeof Derived' but not in type 'typeof Base'. private static x: string; private static fn(): string { return ''; diff --git a/tests/baselines/reference/errorSuperPropertyAccess.errors.txt b/tests/baselines/reference/errorSuperPropertyAccess.errors.txt index 9833e64eba513..a7b8399732a39 100644 --- a/tests/baselines/reference/errorSuperPropertyAccess.errors.txt +++ b/tests/baselines/reference/errorSuperPropertyAccess.errors.txt @@ -79,13 +79,13 @@ super(); super.publicMember = 1; ~~~~~~~~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword } fn() { var x = super.publicMember; ~~~~~~~~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword } get a() { @@ -93,7 +93,7 @@ !!! Accessors are only available when targeting ECMAScript 5 and higher. var x = super.publicMember; ~~~~~~~~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword return undefined; } set a(n) { @@ -101,7 +101,7 @@ !!! Accessors are only available when targeting ECMAScript 5 and higher. n = super.publicMember; ~~~~~~~~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword } fn2() { function inner() { @@ -125,13 +125,13 @@ super(); super.privateMember = 1; ~~~~~~~~~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword } fn() { var x = super.privateMember; ~~~~~~~~~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword } get a() { @@ -139,7 +139,7 @@ !!! Accessors are only available when targeting ECMAScript 5 and higher. var x = super.privateMember; ~~~~~~~~~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword return undefined; } set a(n) { @@ -147,7 +147,7 @@ !!! Accessors are only available when targeting ECMAScript 5 and higher. n = super.privateMember; ~~~~~~~~~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword } } @@ -159,10 +159,10 @@ static fn() { super.publicStaticMember = 3; ~~~~~~~~~~~~~~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword super.privateStaticMember = 3; ~~~~~~~~~~~~~~~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword super.privateStaticFunc(); ~~~~~~~~~~~~~~~~~~~~~~~ !!! Property 'SomeBase.privateStaticFunc' is inaccessible. @@ -172,10 +172,10 @@ !!! Accessors are only available when targeting ECMAScript 5 and higher. super.publicStaticMember = 3; ~~~~~~~~~~~~~~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword super.privateStaticMember = 3; ~~~~~~~~~~~~~~~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword super.privateStaticFunc(); ~~~~~~~~~~~~~~~~~~~~~~~ !!! Property 'SomeBase.privateStaticFunc' is inaccessible. @@ -186,10 +186,10 @@ !!! Accessors are only available when targeting ECMAScript 5 and higher. super.publicStaticMember = 3; ~~~~~~~~~~~~~~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword super.privateStaticMember = 3; ~~~~~~~~~~~~~~~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword super.privateStaticFunc(); ~~~~~~~~~~~~~~~~~~~~~~~ !!! Property 'SomeBase.privateStaticFunc' is inaccessible. diff --git a/tests/baselines/reference/functionOverloadErrors.errors.txt b/tests/baselines/reference/functionOverloadErrors.errors.txt index c2fcff7a943c8..9709853a495de 100644 --- a/tests/baselines/reference/functionOverloadErrors.errors.txt +++ b/tests/baselines/reference/functionOverloadErrors.errors.txt @@ -73,12 +73,12 @@ public f(); private f(s: string); ~ -!!! Overload signatures must all be public or private. +!!! Overload signatures must all be public, private or protected. f() { } private g(s: string); ~ -!!! Overload signatures must all be public or private. +!!! Overload signatures must all be public, private or protected. public g(); g() { } } diff --git a/tests/baselines/reference/functionOverloads5.errors.txt b/tests/baselines/reference/functionOverloads5.errors.txt index a73fb152a0ebe..ef6fd76149aa0 100644 --- a/tests/baselines/reference/functionOverloads5.errors.txt +++ b/tests/baselines/reference/functionOverloads5.errors.txt @@ -2,7 +2,7 @@ class baz { public foo(); ~~~ -!!! Overload signatures must all be public or private. +!!! Overload signatures must all be public, private or protected. private foo(bar?:any){ } } \ No newline at end of file diff --git a/tests/baselines/reference/i3.errors.txt b/tests/baselines/reference/i3.errors.txt index ebdf371ab367f..d940c7061e183 100644 --- a/tests/baselines/reference/i3.errors.txt +++ b/tests/baselines/reference/i3.errors.txt @@ -7,4 +7,4 @@ x = i; ~ !!! Type 'I3' is not assignable to type '{ one: number; }': -!!! Required property 'one' cannot be reimplemented with optional property in 'I3'. \ No newline at end of file +!!! Property 'one' is optional in type 'I3' but required in type '{ one: number; }'. \ No newline at end of file diff --git a/tests/baselines/reference/implementPublicPropertyAsPrivate.errors.txt b/tests/baselines/reference/implementPublicPropertyAsPrivate.errors.txt index 25ffa123d77d1..9200c812e2d47 100644 --- a/tests/baselines/reference/implementPublicPropertyAsPrivate.errors.txt +++ b/tests/baselines/reference/implementPublicPropertyAsPrivate.errors.txt @@ -5,6 +5,6 @@ class C implements I { ~ !!! Class 'C' incorrectly implements interface 'I': -!!! Private property 'x' cannot be reimplemented. +!!! Property 'x' is private in type 'C' but not in type 'I'. private x = 0; // should raise error at class decl } \ No newline at end of file diff --git a/tests/baselines/reference/implementingAnInterfaceExtendingClassWithPrivates.errors.txt b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithPrivates.errors.txt index 22cbf1aacac73..a4b6fa23e6279 100644 --- a/tests/baselines/reference/implementingAnInterfaceExtendingClassWithPrivates.errors.txt +++ b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithPrivates.errors.txt @@ -23,7 +23,7 @@ class Bar3 implements I { // error ~~~~ !!! Class 'Bar3' incorrectly implements interface 'I': -!!! Private property 'x' cannot be reimplemented. +!!! Property 'x' is private in type 'I' but not in type 'Bar3'. x: string; y: number; } @@ -31,7 +31,7 @@ class Bar4 implements I { // error ~~~~ !!! Class 'Bar4' incorrectly implements interface 'I': -!!! Private property 'x' cannot be reimplemented. +!!! Types have separate declarations of a private property 'x'. private x: string; y: number; } \ No newline at end of file diff --git a/tests/baselines/reference/implementingAnInterfaceExtendingClassWithPrivates2.errors.txt b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithPrivates2.errors.txt index 7598e2b613203..04fbc5bacd0fd 100644 --- a/tests/baselines/reference/implementingAnInterfaceExtendingClassWithPrivates2.errors.txt +++ b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithPrivates2.errors.txt @@ -14,10 +14,10 @@ class Bar2 extends Foo implements I { // error ~~~~ !!! Class 'Bar2' incorrectly extends base class 'Foo': -!!! Private property 'x' cannot be reimplemented. +!!! Property 'x' is private in type 'Foo' but not in type 'Bar2'. ~~~~ !!! Class 'Bar2' incorrectly implements interface 'I': -!!! Private property 'x' cannot be reimplemented. +!!! Property 'x' is private in type 'I' but not in type 'Bar2'. x: string; y: number; } @@ -25,10 +25,10 @@ class Bar3 extends Foo implements I { // error ~~~~ !!! Class 'Bar3' incorrectly extends base class 'Foo': -!!! Private property 'x' cannot be reimplemented. +!!! Types have separate declarations of a private property 'x'. ~~~~ !!! Class 'Bar3' incorrectly implements interface 'I': -!!! Private property 'x' cannot be reimplemented. +!!! Types have separate declarations of a private property 'x'. private x: string; y: number; } @@ -55,7 +55,7 @@ class Bar2 extends Foo implements I { // error ~~~~ !!! Class 'Bar2' incorrectly extends base class 'Foo': -!!! Private property 'x' cannot be reimplemented. +!!! Property 'x' is private in type 'Foo' but not in type 'Bar2'. ~~~~ !!! Class 'Bar2' incorrectly implements interface 'I': !!! Property 'z' is missing in type 'Bar2'. @@ -66,7 +66,7 @@ class Bar3 extends Foo implements I { // error ~~~~ !!! Class 'Bar3' incorrectly extends base class 'Foo': -!!! Private property 'x' cannot be reimplemented. +!!! Types have separate declarations of a private property 'x'. ~~~~ !!! Class 'Bar3' incorrectly implements interface 'I': !!! Property 'z' is missing in type 'Bar3'. @@ -108,7 +108,7 @@ class Bar2 extends Foo implements I { // error ~~~~ !!! Class 'Bar2' incorrectly extends base class 'Foo': -!!! Private property 'x' cannot be reimplemented. +!!! Property 'x' is private in type 'Foo' but not in type 'Bar2'. ~~~~ !!! Class 'Bar2' incorrectly implements interface 'I': !!! Property 'y' is missing in type 'Bar2'. @@ -119,7 +119,7 @@ class Bar3 extends Foo implements I { // error ~~~~ !!! Class 'Bar3' incorrectly extends base class 'Foo': -!!! Private property 'x' cannot be reimplemented. +!!! Types have separate declarations of a private property 'x'. ~~~~ !!! Class 'Bar3' incorrectly implements interface 'I': !!! Property 'y' is missing in type 'Bar3'. diff --git a/tests/baselines/reference/inheritanceGrandParentPrivateMemberCollision.errors.txt b/tests/baselines/reference/inheritanceGrandParentPrivateMemberCollision.errors.txt index a59e3da0d0495..d44a2dde4f6f3 100644 --- a/tests/baselines/reference/inheritanceGrandParentPrivateMemberCollision.errors.txt +++ b/tests/baselines/reference/inheritanceGrandParentPrivateMemberCollision.errors.txt @@ -8,7 +8,7 @@ class C extends B { ~ !!! Class 'C' incorrectly extends base class 'B': -!!! Private property 'myMethod' cannot be reimplemented. +!!! Types have separate declarations of a private property 'myMethod'. private myMethod() { } } \ No newline at end of file diff --git a/tests/baselines/reference/inheritanceGrandParentPrivateMemberCollisionWithPublicMember.errors.txt b/tests/baselines/reference/inheritanceGrandParentPrivateMemberCollisionWithPublicMember.errors.txt index ca7a3b32b8e95..4c36b6ad3b73d 100644 --- a/tests/baselines/reference/inheritanceGrandParentPrivateMemberCollisionWithPublicMember.errors.txt +++ b/tests/baselines/reference/inheritanceGrandParentPrivateMemberCollisionWithPublicMember.errors.txt @@ -8,7 +8,7 @@ class C extends B { ~ !!! Class 'C' incorrectly extends base class 'B': -!!! Private property 'myMethod' cannot be reimplemented. +!!! Property 'myMethod' is private in type 'B' but not in type 'C'. public myMethod() { } } \ No newline at end of file diff --git a/tests/baselines/reference/inheritanceGrandParentPublicMemberCollisionWithPrivateMember.errors.txt b/tests/baselines/reference/inheritanceGrandParentPublicMemberCollisionWithPrivateMember.errors.txt index be63f2e9c1efd..49060a4230089 100644 --- a/tests/baselines/reference/inheritanceGrandParentPublicMemberCollisionWithPrivateMember.errors.txt +++ b/tests/baselines/reference/inheritanceGrandParentPublicMemberCollisionWithPrivateMember.errors.txt @@ -8,7 +8,7 @@ class C extends B { ~ !!! Class 'C' incorrectly extends base class 'B': -!!! Private property 'myMethod' cannot be reimplemented. +!!! Property 'myMethod' is private in type 'C' but not in type 'B'. private myMethod() { } } \ No newline at end of file diff --git a/tests/baselines/reference/interfaceExtendingClassWithPrivates.errors.txt b/tests/baselines/reference/interfaceExtendingClassWithPrivates.errors.txt index 525f9e2d517f2..6ff78f80f0b25 100644 --- a/tests/baselines/reference/interfaceExtendingClassWithPrivates.errors.txt +++ b/tests/baselines/reference/interfaceExtendingClassWithPrivates.errors.txt @@ -6,7 +6,7 @@ interface I extends Foo { // error ~ !!! Interface 'I' incorrectly extends interface 'Foo': -!!! Private property 'x' cannot be reimplemented. +!!! Property 'x' is private in type 'Foo' but not in type 'I'. x: string; } diff --git a/tests/baselines/reference/interfaceExtendingClassWithPrivates2.errors.txt b/tests/baselines/reference/interfaceExtendingClassWithPrivates2.errors.txt index 9af19f5f67e85..e4d428325c1cc 100644 --- a/tests/baselines/reference/interfaceExtendingClassWithPrivates2.errors.txt +++ b/tests/baselines/reference/interfaceExtendingClassWithPrivates2.errors.txt @@ -16,10 +16,10 @@ interface I4 extends Foo, Bar { // error ~~ !!! Interface 'I4' incorrectly extends interface 'Bar': -!!! Private property 'x' cannot be reimplemented. +!!! Property 'x' is private in type 'Bar' but not in type 'I4'. ~~ !!! Interface 'I4' incorrectly extends interface 'Foo': -!!! Private property 'x' cannot be reimplemented. +!!! Property 'x' is private in type 'Foo' but not in type 'I4'. x: string; } diff --git a/tests/baselines/reference/interfaceExtendsClassWithPrivate2.errors.txt b/tests/baselines/reference/interfaceExtendsClassWithPrivate2.errors.txt index 54d0ebef980ab..dbf94fc5f9470 100644 --- a/tests/baselines/reference/interfaceExtendsClassWithPrivate2.errors.txt +++ b/tests/baselines/reference/interfaceExtendsClassWithPrivate2.errors.txt @@ -11,10 +11,10 @@ class D extends C implements I { // error ~ !!! Class 'D' incorrectly extends base class 'C': -!!! Private property 'x' cannot be reimplemented. +!!! Types have separate declarations of a private property 'x'. ~ !!! Class 'D' incorrectly implements interface 'I': -!!! Private property 'x' cannot be reimplemented. +!!! Types have separate declarations of a private property 'x'. public foo(x: any) { return x; } private x = 2; private y = 3; @@ -25,10 +25,10 @@ class D2 extends C implements I { // error ~~ !!! Class 'D2' incorrectly extends base class 'C': -!!! Private property 'x' cannot be reimplemented. +!!! Types have separate declarations of a private property 'x'. ~~ !!! Class 'D2' incorrectly implements interface 'I': -!!! Private property 'x' cannot be reimplemented. +!!! Types have separate declarations of a private property 'x'. public foo(x: any) { return x; } private x = ""; other(x: any) { return x; } diff --git a/tests/baselines/reference/interfaceImplementation1.errors.txt b/tests/baselines/reference/interfaceImplementation1.errors.txt index f278e160227df..7a1cc9d2146bc 100644 --- a/tests/baselines/reference/interfaceImplementation1.errors.txt +++ b/tests/baselines/reference/interfaceImplementation1.errors.txt @@ -13,10 +13,10 @@ class C1 implements I1,I2 { ~~ !!! Class 'C1' incorrectly implements interface 'I1': -!!! Private property 'iObj' cannot be reimplemented. +!!! Property 'iObj' is private in type 'C1' but not in type 'I1'. ~~ !!! Class 'C1' incorrectly implements interface 'I2': -!!! Private property 'iFn' cannot be reimplemented. +!!! Property 'iFn' is private in type 'C1' but not in type 'I2'. private iFn(); private iFn(n?:number, s?:string) { } private iAny:any; diff --git a/tests/baselines/reference/interfaceImplementation6.errors.txt b/tests/baselines/reference/interfaceImplementation6.errors.txt index a935fa60c7dcf..3c0dfcf5ecdc8 100644 --- a/tests/baselines/reference/interfaceImplementation6.errors.txt +++ b/tests/baselines/reference/interfaceImplementation6.errors.txt @@ -10,7 +10,7 @@ class C2 implements I1 { ~~ !!! Class 'C2' incorrectly implements interface 'I1': -!!! Private property 'item' cannot be reimplemented. +!!! Property 'item' is private in type 'C2' but not in type 'I1'. private item:number; } diff --git a/tests/baselines/reference/interfaceImplementation8.errors.txt b/tests/baselines/reference/interfaceImplementation8.errors.txt index 6218ecd6a5e34..8ac23e82079f8 100644 --- a/tests/baselines/reference/interfaceImplementation8.errors.txt +++ b/tests/baselines/reference/interfaceImplementation8.errors.txt @@ -13,7 +13,7 @@ class C2 implements i1 { ~~ !!! Class 'C2' incorrectly implements interface 'i1': -!!! Private property 'name' cannot be reimplemented. +!!! Property 'name' is private in type 'C2' but not in type 'i1'. private name:string; } @@ -25,11 +25,11 @@ class C5 extends C2 implements i1{ } ~~ !!! Class 'C5' incorrectly implements interface 'i1': -!!! Private property 'name' cannot be reimplemented. +!!! Property 'name' is private in type 'C5' but not in type 'i1'. class C6 extends C3 implements i1{ } ~~ !!! Class 'C6' incorrectly implements interface 'i1': -!!! Private property 'name' cannot be reimplemented. +!!! Property 'name' is private in type 'C6' but not in type 'i1'. /* 2 diff --git a/tests/baselines/reference/interfaceWithPropertyThatIsPrivateInBaseType.errors.txt b/tests/baselines/reference/interfaceWithPropertyThatIsPrivateInBaseType.errors.txt index 543e7fc9ce88e..6fe5bf3cd4d9e 100644 --- a/tests/baselines/reference/interfaceWithPropertyThatIsPrivateInBaseType.errors.txt +++ b/tests/baselines/reference/interfaceWithPropertyThatIsPrivateInBaseType.errors.txt @@ -6,7 +6,7 @@ interface Foo extends Base { // error ~~~ !!! Interface 'Foo' incorrectly extends interface 'Base': -!!! Private property 'x' cannot be reimplemented. +!!! Property 'x' is private in type 'Base' but not in type 'Foo'. x: number; } @@ -17,6 +17,6 @@ interface Foo2 extends Base2 { // error ~~~~ !!! Interface 'Foo2' incorrectly extends interface 'Base2': -!!! Private property 'x' cannot be reimplemented. +!!! Property 'x' is private in type 'Base2' but not in type 'Foo2'. x: number; } \ No newline at end of file diff --git a/tests/baselines/reference/interfaceWithPropertyThatIsPrivateInBaseType2.errors.txt b/tests/baselines/reference/interfaceWithPropertyThatIsPrivateInBaseType2.errors.txt index f056d65fe1616..f91d818e5a9b5 100644 --- a/tests/baselines/reference/interfaceWithPropertyThatIsPrivateInBaseType2.errors.txt +++ b/tests/baselines/reference/interfaceWithPropertyThatIsPrivateInBaseType2.errors.txt @@ -6,7 +6,7 @@ interface Foo extends Base { // error ~~~ !!! Interface 'Foo' incorrectly extends interface 'Base': -!!! Private property 'x' cannot be reimplemented. +!!! Property 'x' is private in type 'Base' but not in type 'Foo'. x(): any; } @@ -17,6 +17,6 @@ interface Foo2 extends Base2 { // error ~~~~ !!! Interface 'Foo2' incorrectly extends interface 'Base2': -!!! Private property 'x' cannot be reimplemented. +!!! Property 'x' is private in type 'Base2' but not in type 'Foo2'. x(): any; } \ No newline at end of file diff --git a/tests/baselines/reference/memberFunctionsWithPublicPrivateOverloads.errors.txt b/tests/baselines/reference/memberFunctionsWithPublicPrivateOverloads.errors.txt index 962a00d95347b..ef080666bcf9e 100644 --- a/tests/baselines/reference/memberFunctionsWithPublicPrivateOverloads.errors.txt +++ b/tests/baselines/reference/memberFunctionsWithPublicPrivateOverloads.errors.txt @@ -3,26 +3,26 @@ private foo(x: number); public foo(x: number, y: string); // error ~~~ -!!! Overload signatures must all be public or private. +!!! Overload signatures must all be public, private or protected. private foo(x: any, y?: any) { } private bar(x: 'hi'); public bar(x: string); // error ~~~ -!!! Overload signatures must all be public or private. +!!! Overload signatures must all be public, private or protected. private bar(x: number, y: string); private bar(x: any, y?: any) { } private static foo(x: number); public static foo(x: number, y: string); // error ~~~ -!!! Overload signatures must all be public or private. +!!! Overload signatures must all be public, private or protected. private static foo(x: any, y?: any) { } private static bar(x: 'hi'); public static bar(x: string); // error ~~~ -!!! Overload signatures must all be public or private. +!!! Overload signatures must all be public, private or protected. private static bar(x: number, y: string); private static bar(x: any, y?: any) { } } @@ -31,26 +31,26 @@ private foo(x: number); public foo(x: T, y: T); // error ~~~ -!!! Overload signatures must all be public or private. +!!! Overload signatures must all be public, private or protected. private foo(x: any, y?: any) { } private bar(x: 'hi'); public bar(x: string); // error ~~~ -!!! Overload signatures must all be public or private. +!!! Overload signatures must all be public, private or protected. private bar(x: T, y: T); private bar(x: any, y?: any) { } private static foo(x: number); public static foo(x: number, y: string); // error ~~~ -!!! Overload signatures must all be public or private. +!!! Overload signatures must all be public, private or protected. private static foo(x: any, y?: any) { } private static bar(x: 'hi'); public static bar(x: string); // error ~~~ -!!! Overload signatures must all be public or private. +!!! Overload signatures must all be public, private or protected. private static bar(x: number, y: string); private static bar(x: any, y?: any) { } } diff --git a/tests/baselines/reference/mergedInterfacesWithInheritedPrivates.errors.txt b/tests/baselines/reference/mergedInterfacesWithInheritedPrivates.errors.txt index 3ad843c7f17df..65d057e55fe01 100644 --- a/tests/baselines/reference/mergedInterfacesWithInheritedPrivates.errors.txt +++ b/tests/baselines/reference/mergedInterfacesWithInheritedPrivates.errors.txt @@ -14,7 +14,7 @@ class D implements A { // error ~ !!! Class 'D' incorrectly implements interface 'A': -!!! Private property 'x' cannot be reimplemented. +!!! Types have separate declarations of a private property 'x'. private x: number; y: string; z: string; @@ -23,7 +23,7 @@ class E implements A { // error ~ !!! Class 'E' incorrectly implements interface 'A': -!!! Private property 'x' cannot be reimplemented. +!!! Property 'x' is private in type 'A' but not in type 'E'. x: number; y: string; z: string; diff --git a/tests/baselines/reference/mergedInterfacesWithInheritedPrivates2.errors.txt b/tests/baselines/reference/mergedInterfacesWithInheritedPrivates2.errors.txt index 7ab40587207af..3f1aa603014ed 100644 --- a/tests/baselines/reference/mergedInterfacesWithInheritedPrivates2.errors.txt +++ b/tests/baselines/reference/mergedInterfacesWithInheritedPrivates2.errors.txt @@ -18,7 +18,7 @@ class D extends C implements A { // error ~ !!! Class 'D' incorrectly implements interface 'A': -!!! Private property 'w' cannot be reimplemented. +!!! Types have separate declarations of a private property 'w'. private w: number; y: string; z: string; @@ -27,7 +27,7 @@ class E extends C2 implements A { // error ~ !!! Class 'E' incorrectly extends base class 'C2': -!!! Private property 'w' cannot be reimplemented. +!!! Property 'w' is private in type 'C2' but not in type 'E'. ~ !!! Class 'E' incorrectly implements interface 'A': !!! Property 'x' is missing in type 'E'. diff --git a/tests/baselines/reference/optionalPropertiesTest.errors.txt b/tests/baselines/reference/optionalPropertiesTest.errors.txt index 8068dd5e061cf..46cab0654dc46 100644 --- a/tests/baselines/reference/optionalPropertiesTest.errors.txt +++ b/tests/baselines/reference/optionalPropertiesTest.errors.txt @@ -50,4 +50,4 @@ test10_1 = test10_2; ~~~~~~~~ !!! Type 'i2' is not assignable to type 'i1': -!!! Required property 'M' cannot be reimplemented with optional property in 'i2'. \ No newline at end of file +!!! Property 'M' is optional in type 'i2' but required in type 'i1'. \ No newline at end of file diff --git a/tests/baselines/reference/overloadModifiersMustAgree.errors.txt b/tests/baselines/reference/overloadModifiersMustAgree.errors.txt index f2aa56b8e4d0b..bafb84be8694f 100644 --- a/tests/baselines/reference/overloadModifiersMustAgree.errors.txt +++ b/tests/baselines/reference/overloadModifiersMustAgree.errors.txt @@ -2,7 +2,7 @@ class baz { public foo(); ~~~ -!!! Overload signatures must all be public or private. +!!! Overload signatures must all be public, private or protected. private foo(bar?: any) { } // error - access modifiers do not agree } diff --git a/tests/baselines/reference/overridingPrivateStaticMembers.errors.txt b/tests/baselines/reference/overridingPrivateStaticMembers.errors.txt index 0e7200d122d08..f8db183ea4386 100644 --- a/tests/baselines/reference/overridingPrivateStaticMembers.errors.txt +++ b/tests/baselines/reference/overridingPrivateStaticMembers.errors.txt @@ -6,6 +6,6 @@ class Derived2 extends Base2 { ~~~~~~~~ !!! Class static side 'typeof Derived2' incorrectly extends base class static side 'typeof Base2': -!!! Private property 'y' cannot be reimplemented. +!!! Types have separate declarations of a private property 'y'. private static y: { foo: string; bar: string; }; } \ No newline at end of file diff --git a/tests/baselines/reference/parserAstSpans1.errors.txt b/tests/baselines/reference/parserAstSpans1.errors.txt index e4e6aaef5553c..fe334aae7811a 100644 --- a/tests/baselines/reference/parserAstSpans1.errors.txt +++ b/tests/baselines/reference/parserAstSpans1.errors.txt @@ -119,7 +119,7 @@ super(10); this.p1 = super.c2_p1; ~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword } /** c3 p1*/ public p1: number; @@ -231,6 +231,6 @@ super(); this.d = super.b; ~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword } } \ No newline at end of file diff --git a/tests/baselines/reference/privateInstanceMemberAccessibility.errors.txt b/tests/baselines/reference/privateInstanceMemberAccessibility.errors.txt index e3eddca5b8b4c..0e12c399a76c4 100644 --- a/tests/baselines/reference/privateInstanceMemberAccessibility.errors.txt +++ b/tests/baselines/reference/privateInstanceMemberAccessibility.errors.txt @@ -6,17 +6,17 @@ class Derived extends Base { x = super.foo; // error ~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword y() { return super.foo; // error ~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword } z: typeof super.foo; // error ~~~~~ !!! Identifier expected. ~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword a: this.foo; // error ~~~~ diff --git a/tests/baselines/reference/privateInterfaceProperties.errors.txt b/tests/baselines/reference/privateInterfaceProperties.errors.txt index 99d47794c9bde..a9beb7ea20a99 100644 --- a/tests/baselines/reference/privateInterfaceProperties.errors.txt +++ b/tests/baselines/reference/privateInterfaceProperties.errors.txt @@ -5,7 +5,7 @@ class c1 implements i1 { private name:string; } ~~ !!! Class 'c1' incorrectly implements interface 'i1': -!!! Private property 'name' cannot be reimplemented. +!!! Property 'name' is private in type 'c1' but not in type 'i1'. // should be ok class c2 implements i1 { public name:string; } diff --git a/tests/baselines/reference/propertyParameterWithQuestionMark.errors.txt b/tests/baselines/reference/propertyParameterWithQuestionMark.errors.txt index c58b23452054f..56eb55e6a0f37 100644 --- a/tests/baselines/reference/propertyParameterWithQuestionMark.errors.txt +++ b/tests/baselines/reference/propertyParameterWithQuestionMark.errors.txt @@ -12,5 +12,5 @@ v = v2; // Should fail ~ !!! Type '{ x?: any; }' is not assignable to type 'C': -!!! Required property 'x' cannot be reimplemented with optional property in '{ x?: any; }'. +!!! Property 'x' is optional in type '{ x?: any; }' but required in type 'C'. var v3: { x } = new C; // Should succeed \ No newline at end of file diff --git a/tests/baselines/reference/protectedMembers.errors.txt b/tests/baselines/reference/protectedMembers.errors.txt new file mode 100644 index 0000000000000..8c23643e57bf6 --- /dev/null +++ b/tests/baselines/reference/protectedMembers.errors.txt @@ -0,0 +1,148 @@ +==== tests/cases/compiler/protectedMembers.ts (14 errors) ==== + // Class with protected members + class C1 { + protected x: number; + protected static sx: number; + protected f() { + return this.x; + } + protected static sf() { + return this.sx; + } + } + + // Derived class accessing protected members + class C2 extends C1 { + protected f() { + return super.f() + this.x; + } + protected static sf() { + return super.sf() + this.sx; + } + } + + // Derived class making protected members public + class C3 extends C2 { + x: number; + static sx: number; + f() { + return super.f(); + } + static sf() { + return super.sf(); + } + } + + var c1: C1; + var c2: C2; + var c3: C3; + + // All of these should be errors + c1.x; + ~~~~ +!!! Property 'C1.x' is inaccessible. + c1.f(); + ~~~~ +!!! Property 'C1.f' is inaccessible. + C1.sx; + ~~~~~ +!!! Property 'C1.sx' is inaccessible. + C1.sf(); + ~~~~~ +!!! Property 'C1.sf' is inaccessible. + + // All of these should be errors + c2.x; + ~~~~ +!!! Property 'C1.x' is inaccessible. + c2.f(); + ~~~~ +!!! Property 'C2.f' is inaccessible. + C2.sx; + ~~~~~ +!!! Property 'C1.sx' is inaccessible. + C2.sf(); + ~~~~~ +!!! Property 'C2.sf' is inaccessible. + + // All of these should be ok + c3.x; + c3.f(); + C3.sx; + C3.sf(); + + class A { + protected x; + } + + class B extends A { + y; + } + + class C extends A { + z; + static foo(a: A, b: B, c: C, d: D, e: E) { + a.x = 1; // Error, access must be through C or type derived from C + ~~~ +!!! Property 'A.x' is inaccessible. + b.x = 1; // Error, access must be through C or type derived from C + ~~~ +!!! Property 'A.x' is inaccessible. + c.x = 1; + d.x = 1; + e.x = 1; + } + } + + class D extends C { + d; + } + + interface E extends C { + e; + } + + class CC { + // Error, constructor cannot be protected + protected constructor() { + ~~~~~~~~~ +!!! 'protected' modifier cannot appear on a constructor declaration. + } + } + + class A1 { + protected x; + } + class B1 { + x; + } + var a1: A1; + var b1: B1; + a1 = b1; // Error, B1 doesn't derive from A1 + ~~ +!!! Type 'B1' is not assignable to type 'A1': +!!! Property 'x' is protected but type 'B1' is not derived from type 'A1'. + b1 = a1; // Error, x is protected in A1 but public in B1 + ~~ +!!! Type 'A1' is not assignable to type 'B1': +!!! Property 'x' is protected in type 'A1' but public in type 'B1'. + + class A2 { + protected x; + } + class B2 extends A2 { + x; + } + + class A3 { + x; + } + // Error x is protected in B3 but public in A3 + class B3 extends A3 { + ~~ +!!! Class 'B3' incorrectly extends base class 'A3': +!!! Property 'x' is protected in type 'B3' but public in type 'A3'. + protected x; + } + + \ No newline at end of file diff --git a/tests/baselines/reference/publicMemberImplementedAsPrivateInDerivedClass.errors.txt b/tests/baselines/reference/publicMemberImplementedAsPrivateInDerivedClass.errors.txt index 17771c365c5fe..86f34082a922a 100644 --- a/tests/baselines/reference/publicMemberImplementedAsPrivateInDerivedClass.errors.txt +++ b/tests/baselines/reference/publicMemberImplementedAsPrivateInDerivedClass.errors.txt @@ -5,7 +5,7 @@ class Foo implements Qux { ~~~ !!! Class 'Foo' incorrectly implements interface 'Qux': -!!! Private property 'Bar' cannot be reimplemented. +!!! Property 'Bar' is private in type 'Foo' but not in type 'Qux'. private Bar: number; } \ No newline at end of file diff --git a/tests/baselines/reference/scopeTests.errors.txt b/tests/baselines/reference/scopeTests.errors.txt index 5c2d07247a3ce..4ab27e5b766ad 100644 --- a/tests/baselines/reference/scopeTests.errors.txt +++ b/tests/baselines/reference/scopeTests.errors.txt @@ -3,7 +3,7 @@ class D extends C { ~ !!! Class 'D' incorrectly extends base class 'C': -!!! Private property 'v' cannot be reimplemented. +!!! Property 'v' is private in type 'C' but not in type 'D'. public v: number; public p: number constructor() { diff --git a/tests/baselines/reference/shadowPrivateMembers.errors.txt b/tests/baselines/reference/shadowPrivateMembers.errors.txt index 8b9bfffb912ca..ddf8ca718778a 100644 --- a/tests/baselines/reference/shadowPrivateMembers.errors.txt +++ b/tests/baselines/reference/shadowPrivateMembers.errors.txt @@ -3,5 +3,5 @@ class derived extends base { private n() {} } ~~~~~~~ !!! Class 'derived' incorrectly extends base class 'base': -!!! Private property 'n' cannot be reimplemented. +!!! Types have separate declarations of a private property 'n'. \ No newline at end of file diff --git a/tests/baselines/reference/subtypingWithObjectMembersAccessibility.errors.txt b/tests/baselines/reference/subtypingWithObjectMembersAccessibility.errors.txt index 7c29926b65c58..1945f56ab4c0c 100644 --- a/tests/baselines/reference/subtypingWithObjectMembersAccessibility.errors.txt +++ b/tests/baselines/reference/subtypingWithObjectMembersAccessibility.errors.txt @@ -16,7 +16,7 @@ class B extends A { ~ !!! Class 'B' incorrectly extends base class 'A': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'B' but not in type 'A'. private foo: Derived; // error } @@ -27,7 +27,7 @@ class B2 extends A2 { ~~ !!! Class 'B2' incorrectly extends base class 'A2': -!!! Private property '1' cannot be reimplemented. +!!! Property '1' is private in type 'B2' but not in type 'A2'. private 1: Derived; // error } @@ -38,6 +38,6 @@ class B3 extends A3 { ~~ !!! Class 'B3' incorrectly extends base class 'A3': -!!! Private property ''1'' cannot be reimplemented. +!!! Property ''1'' is private in type 'B3' but not in type 'A3'. private '1': Derived; // error } \ No newline at end of file diff --git a/tests/baselines/reference/subtypingWithObjectMembersAccessibility2.errors.txt b/tests/baselines/reference/subtypingWithObjectMembersAccessibility2.errors.txt index d8d3d34efb237..e22088ea4c5f1 100644 --- a/tests/baselines/reference/subtypingWithObjectMembersAccessibility2.errors.txt +++ b/tests/baselines/reference/subtypingWithObjectMembersAccessibility2.errors.txt @@ -17,7 +17,7 @@ class B extends A { ~ !!! Class 'B' incorrectly extends base class 'A': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'A' but not in type 'B'. public foo: Derived; // error } @@ -28,7 +28,7 @@ class B2 extends A2 { ~~ !!! Class 'B2' incorrectly extends base class 'A2': -!!! Private property '1' cannot be reimplemented. +!!! Property '1' is private in type 'A2' but not in type 'B2'. public 1: Derived; // error } @@ -39,7 +39,7 @@ class B3 extends A3 { ~~ !!! Class 'B3' incorrectly extends base class 'A3': -!!! Private property ''1'' cannot be reimplemented. +!!! Property ''1'' is private in type 'A3' but not in type 'B3'. public '1': Derived; // error } } @@ -52,7 +52,7 @@ class B extends A { ~ !!! Class 'B' incorrectly extends base class 'A': -!!! Private property 'foo' cannot be reimplemented. +!!! Property 'foo' is private in type 'A' but not in type 'B'. foo: Derived; // error } @@ -63,7 +63,7 @@ class B2 extends A2 { ~~ !!! Class 'B2' incorrectly extends base class 'A2': -!!! Private property '1' cannot be reimplemented. +!!! Property '1' is private in type 'A2' but not in type 'B2'. 1: Derived; // error } @@ -74,7 +74,7 @@ class B3 extends A3 { ~~ !!! Class 'B3' incorrectly extends base class 'A3': -!!! Private property ''1'' cannot be reimplemented. +!!! Property ''1'' is private in type 'A3' but not in type 'B3'. '1': Derived; // error } } \ No newline at end of file diff --git a/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt b/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt index 839d0e5a8ab29..db272d5e49852 100644 --- a/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt +++ b/tests/baselines/reference/subtypingWithObjectMembersOptionality2.errors.txt @@ -11,7 +11,7 @@ interface S extends T { ~ !!! Interface 'S' incorrectly extends interface 'T': -!!! Required property 'Foo' cannot be reimplemented with optional property in 'S'. +!!! Property 'Foo' is optional in type 'S' but required in type 'T'. Foo?: Derived // error } @@ -22,7 +22,7 @@ interface S2 extends T2 { ~~ !!! Interface 'S2' incorrectly extends interface 'T2': -!!! Required property '1' cannot be reimplemented with optional property in 'S2'. +!!! Property '1' is optional in type 'S2' but required in type 'T2'. 1?: Derived; // error } @@ -33,7 +33,7 @@ interface S3 extends T3 { ~~ !!! Interface 'S3' incorrectly extends interface 'T3': -!!! Required property '1' cannot be reimplemented with optional property in 'S3'. +!!! Property ''1'' is optional in type 'S3' but required in type 'T3'. '1'?: Derived; // error } diff --git a/tests/baselines/reference/superAccess.errors.txt b/tests/baselines/reference/superAccess.errors.txt index 8fa5d21524a80..7ca9d38c3e9dd 100644 --- a/tests/baselines/reference/superAccess.errors.txt +++ b/tests/baselines/reference/superAccess.errors.txt @@ -12,9 +12,9 @@ !!! Property 'S1' does not exist on type 'MyBase'. var l4 = super.S2; // Expected => Error: Only public instance methods of the base class are accessible via the 'super' keyword ~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword var l5 = super.f(); // Expected => Error: Only public instance methods of the base class are accessible via the 'super' keyword ~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword } } \ No newline at end of file diff --git a/tests/baselines/reference/superInLambdas.errors.txt b/tests/baselines/reference/superInLambdas.errors.txt index aafed991922b7..bd0f284782994 100644 --- a/tests/baselines/reference/superInLambdas.errors.txt +++ b/tests/baselines/reference/superInLambdas.errors.txt @@ -47,13 +47,13 @@ // super property in a nested lambda in a constructor var superName = () => () => () => super.name; ~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword } sayHello(): void { // super property in a nested lambda in a method var superName = () => () => () => super.name; ~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword } } diff --git a/tests/baselines/reference/superPropertyAccess.errors.txt b/tests/baselines/reference/superPropertyAccess.errors.txt index 4f97d74aa7bd9..cfbc64a43c99d 100644 --- a/tests/baselines/reference/superPropertyAccess.errors.txt +++ b/tests/baselines/reference/superPropertyAccess.errors.txt @@ -26,7 +26,7 @@ super.m2.bind(this); // Should error, instance property, not a public instance member function ~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword super.p1(); // Should error, private not public instance member function ~~~~~~~~ @@ -34,20 +34,20 @@ var l1 = super.d1; // Should error, instance data property not a public instance member function ~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword var l1 = super.d2; // Should error, instance data property not a public instance member function ~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword super.m1 = function (a: string) { return ""; }; // Should be allowed, we will not restrict assignment super.value = 0; // Should error, instance data property not a public instance member function ~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword var z = super.value; // Should error, instance data property not a public instance member function ~~~~~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword } } \ No newline at end of file diff --git a/tests/baselines/reference/superPropertyAccess1.errors.txt b/tests/baselines/reference/superPropertyAccess1.errors.txt index 50add58048c1c..99caeb36e80fd 100644 --- a/tests/baselines/reference/superPropertyAccess1.errors.txt +++ b/tests/baselines/reference/superPropertyAccess1.errors.txt @@ -15,7 +15,7 @@ super.bar(); super.x; // error ~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword } constructor() { @@ -23,7 +23,7 @@ super.bar(); super.x; // error ~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword } public get y() { @@ -32,7 +32,7 @@ super.bar(); super.x; // error ~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword return 1; } } \ No newline at end of file diff --git a/tests/baselines/reference/superPropertyAccess2.errors.txt b/tests/baselines/reference/superPropertyAccess2.errors.txt index abf5193141b39..d76178d727df1 100644 --- a/tests/baselines/reference/superPropertyAccess2.errors.txt +++ b/tests/baselines/reference/superPropertyAccess2.errors.txt @@ -25,7 +25,7 @@ !!! Property 'bar' does not exist on type 'C'. super.x; // error ~ -!!! Only public methods of the base class are accessible via the 'super' keyword +!!! Only public and protected methods of the base class are accessible via the 'super' keyword } public static get y() { diff --git a/tests/baselines/reference/typeIdentityConsidersBrands.errors.txt b/tests/baselines/reference/typeIdentityConsidersBrands.errors.txt index 82b546a981efd..76036e372a020 100644 --- a/tests/baselines/reference/typeIdentityConsidersBrands.errors.txt +++ b/tests/baselines/reference/typeIdentityConsidersBrands.errors.txt @@ -31,7 +31,7 @@ a2 = b2; // should error ~~ !!! Type 'X_1' is not assignable to type 'Y_1': -!!! Private property 'name' cannot be reimplemented. +!!! Types have separate declarations of a private property 'name'. foo2(a2); // should error ~~ !!! Argument of type 'Y_1' is not assignable to parameter of type 'X_1'. diff --git a/tests/baselines/reference/typeMatch1.errors.txt b/tests/baselines/reference/typeMatch1.errors.txt index c1f9e61114cb2..94cb6dfb67a12 100644 --- a/tests/baselines/reference/typeMatch1.errors.txt +++ b/tests/baselines/reference/typeMatch1.errors.txt @@ -19,7 +19,7 @@ x6 = x7; ~~ !!! Type 'D' is not assignable to type 'C': -!!! Private property 'x' cannot be reimplemented. +!!! Types have separate declarations of a private property 'x'. x6=C; ~~ !!! Type 'typeof C' is not assignable to type 'C': diff --git a/tests/cases/compiler/protectedMembers.ts b/tests/cases/compiler/protectedMembers.ts new file mode 100644 index 0000000000000..ae32e47242505 --- /dev/null +++ b/tests/cases/compiler/protectedMembers.ts @@ -0,0 +1,115 @@ +// Class with protected members +class C1 { + protected x: number; + protected static sx: number; + protected f() { + return this.x; + } + protected static sf() { + return this.sx; + } +} + +// Derived class accessing protected members +class C2 extends C1 { + protected f() { + return super.f() + this.x; + } + protected static sf() { + return super.sf() + this.sx; + } +} + +// Derived class making protected members public +class C3 extends C2 { + x: number; + static sx: number; + f() { + return super.f(); + } + static sf() { + return super.sf(); + } +} + +var c1: C1; +var c2: C2; +var c3: C3; + +// All of these should be errors +c1.x; +c1.f(); +C1.sx; +C1.sf(); + +// All of these should be errors +c2.x; +c2.f(); +C2.sx; +C2.sf(); + +// All of these should be ok +c3.x; +c3.f(); +C3.sx; +C3.sf(); + +class A { + protected x; +} + +class B extends A { + y; +} + +class C extends A { + z; + static foo(a: A, b: B, c: C, d: D, e: E) { + a.x = 1; // Error, access must be through C or type derived from C + b.x = 1; // Error, access must be through C or type derived from C + c.x = 1; + d.x = 1; + e.x = 1; + } +} + +class D extends C { + d; +} + +interface E extends C { + e; +} + +class CC { + // Error, constructor cannot be protected + protected constructor() { + } +} + +class A1 { + protected x; +} +class B1 { + x; +} +var a1: A1; +var b1: B1; +a1 = b1; // Error, B1 doesn't derive from A1 +b1 = a1; // Error, x is protected in A1 but public in B1 + +class A2 { + protected x; +} +class B2 extends A2 { + x; +} + +class A3 { + x; +} +// Error x is protected in B3 but public in A3 +class B3 extends A3 { + protected x; +} + From 4aa04a93b3b0c74d2859801e289a978ff2298f79 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Wed, 17 Sep 2014 16:36:38 -0700 Subject: [PATCH 2/5] Addressing CR feedback --- src/compiler/checker.ts | 17 +++++++++++++---- src/compiler/diagnosticMessages.json | 12 ++++++------ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index c6d61c7954ae8..8b3f21bf0b1c8 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2713,12 +2713,12 @@ module ts { if (sourceProp === targetProp) { return true; } - var sourcePropVisibility = getDeclarationFlagsFromSymbol(sourceProp) & (NodeFlags.Private || NodeFlags.Protected); - var targetPropVisibility = getDeclarationFlagsFromSymbol(targetProp) & (NodeFlags.Private || NodeFlags.Protected); - if (sourcePropVisibility !== targetPropVisibility) { + var sourcePropAccessibility = getDeclarationFlagsFromSymbol(sourceProp) & (NodeFlags.Private | NodeFlags.Protected); + var targetPropAccessibility = getDeclarationFlagsFromSymbol(targetProp) & (NodeFlags.Private | NodeFlags.Protected); + if (sourcePropAccessibility !== targetPropAccessibility) { return false; } - if (sourcePropVisibility) { + if (sourcePropAccessibility) { return getTargetSymbol(sourceProp) === getTargetSymbol(targetProp) && relate(getTypeOfSymbol(sourceProp), getTypeOfSymbol(targetProp), reportErrors); } else { @@ -4011,26 +4011,35 @@ module ts { function isClassPropertyAccessible(node: PropertyAccess, type: Type, prop: Symbol): boolean { var flags = getDeclarationFlagsFromSymbol(prop); + // Public properties are always accessible if (!(flags & (NodeFlags.Private | NodeFlags.Protected))) { return true; } + // Property is known to be private or protected at this point + // Private and protected properties are never accessible outside a class declaration var enclosingClassDeclaration = getAncestor(node, SyntaxKind.ClassDeclaration); if (!enclosingClassDeclaration) { return false; } + // Get the declaring and enclosing class instance types var declaringClass = getDeclaredTypeOfSymbol(prop.parent); var enclosingClass = getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)); + // Private property is accessible if declaring and enclosing class are the same if (flags & NodeFlags.Private) { return declaringClass === enclosingClass; } + // Property is known to be protected at this point + // All protected properties of a supertype are accessible in a super access if (node.left.kind === SyntaxKind.SuperKeyword) { return true; } + // An instance property must be accessed through an instance of the enclosing class if (!(flags & NodeFlags.Static)) { if (!(getTargetType(type).flags & (TypeFlags.Class | TypeFlags.Interface) && hasBaseType(type, enclosingClass))) { return false; } } + // A protected property is accessible in the declaring class and classes derived from it return hasBaseType(enclosingClass, declaringClass); } diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index 2e4ed8ce7a983..ba2c87180c92c 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -1012,18 +1012,18 @@ "category": "Error", "code": 2441 }, - "Types have separate declarations of a private property '{0}'.": { + "Types have separate declarations of a private property '{0}'.": { "category": "Error", "code": 2442 - }, - "Property '{0}' is protected but type '{1}' is not derived from type '{2}'.": { + }, + "Property '{0}' is protected but type '{1}' is not a class derived from type '{2}'.": { "category": "Error", "code": 2443 - }, - "Property '{0}' is protected in type '{1}' but public in type '{2}'.": { + }, + "Property '{0}' is protected in type '{1}' but public in type '{2}'.": { "category": "Error", "code": 2444 - }, + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", From c990c4282dfe88d0a4cdea8e70e3b5cee5a1e102 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 19 Sep 2014 06:35:59 -0700 Subject: [PATCH 3/5] Improved error messages for private and protected member access --- src/compiler/checker.ts | 42 ++++++++++--------- .../diagnosticInformationMap.generated.ts | 6 ++- src/compiler/diagnosticMessages.json | 12 +++++- 3 files changed, 37 insertions(+), 23 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 292dfb4bfc637..cc02323b291ae 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -2972,7 +2972,7 @@ module ts { var targetClass = getDeclaredTypeOfSymbol(targetProp.parent); if (!sourceClass || !hasBaseType(sourceClass, targetClass)) { if (reportErrors) { - reportError(Diagnostics.Property_0_is_protected_but_type_1_is_not_derived_from_type_2, + reportError(Diagnostics.Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2, symbolToString(targetProp), typeToString(sourceClass || source), typeToString(targetClass)); } return false; @@ -4012,38 +4012,42 @@ module ts { return s.valueDeclaration ? s.valueDeclaration.flags : s.flags & SymbolFlags.Prototype ? NodeFlags.Public | NodeFlags.Static : 0; } - function isClassPropertyAccessible(node: PropertyAccess, type: Type, prop: Symbol): boolean { + function checkClassPropertyAccess(node: PropertyAccess, type: Type, prop: Symbol) { var flags = getDeclarationFlagsFromSymbol(prop); // Public properties are always accessible if (!(flags & (NodeFlags.Private | NodeFlags.Protected))) { - return true; + return; } // Property is known to be private or protected at this point - // Private and protected properties are never accessible outside a class declaration - var enclosingClassDeclaration = getAncestor(node, SyntaxKind.ClassDeclaration); - if (!enclosingClassDeclaration) { - return false; - } // Get the declaring and enclosing class instance types + var enclosingClassDeclaration = getAncestor(node, SyntaxKind.ClassDeclaration); + var enclosingClass = enclosingClassDeclaration ? getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)) : undefined; var declaringClass = getDeclaredTypeOfSymbol(prop.parent); - var enclosingClass = getDeclaredTypeOfSymbol(getSymbolOfNode(enclosingClassDeclaration)); // Private property is accessible if declaring and enclosing class are the same if (flags & NodeFlags.Private) { - return declaringClass === enclosingClass; + if (declaringClass !== enclosingClass) { + error(node, Diagnostics.Property_0_is_private_and_only_accessible_within_class_1, symbolToString(prop), typeToString(declaringClass)); + } + return; } // Property is known to be protected at this point // All protected properties of a supertype are accessible in a super access if (node.left.kind === SyntaxKind.SuperKeyword) { - return true; + return; + } + // A protected property is accessible in the declaring class and classes derived from it + if (!enclosingClass || !hasBaseType(enclosingClass, declaringClass)) { + error(node, Diagnostics.Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses, symbolToString(prop), typeToString(declaringClass)); + return; + } + // No further restrictions for static properties + if (flags & NodeFlags.Static) { + return; } // An instance property must be accessed through an instance of the enclosing class - if (!(flags & NodeFlags.Static)) { - if (!(getTargetType(type).flags & (TypeFlags.Class | TypeFlags.Interface) && hasBaseType(type, enclosingClass))) { - return false; - } + if (!(getTargetType(type).flags & (TypeFlags.Class | TypeFlags.Interface) && hasBaseType(type, enclosingClass))) { + error(node, Diagnostics.Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1, symbolToString(prop), typeToString(enclosingClass)); } - // A protected property is accessible in the declaring class and classes derived from it - return hasBaseType(enclosingClass, declaringClass); } function checkPropertyAccess(node: PropertyAccess) { @@ -4074,8 +4078,8 @@ module ts { if (node.left.kind === SyntaxKind.SuperKeyword && getDeclarationKindFromSymbol(prop) !== SyntaxKind.Method) { error(node.right, Diagnostics.Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword); } - else if (!isClassPropertyAccessible(node, type, prop)) { - error(node, Diagnostics.Property_0_is_inaccessible, getFullyQualifiedName(prop)); + else { + checkClassPropertyAccess(node, type, prop); } } return getTypeOfSymbol(prop); diff --git a/src/compiler/diagnosticInformationMap.generated.ts b/src/compiler/diagnosticInformationMap.generated.ts index 772a386af2c22..ba6f742c4c14c 100644 --- a/src/compiler/diagnosticInformationMap.generated.ts +++ b/src/compiler/diagnosticInformationMap.generated.ts @@ -154,7 +154,7 @@ module ts { super_property_access_is_permitted_only_in_a_constructor_member_function_or_member_accessor_of_a_derived_class: { code: 2338, category: DiagnosticCategory.Error, key: "'super' property access is permitted only in a constructor, member function, or member accessor of a derived class" }, Property_0_does_not_exist_on_type_1: { code: 2339, category: DiagnosticCategory.Error, key: "Property '{0}' does not exist on type '{1}'." }, Only_public_and_protected_methods_of_the_base_class_are_accessible_via_the_super_keyword: { code: 2340, category: DiagnosticCategory.Error, key: "Only public and protected methods of the base class are accessible via the 'super' keyword" }, - Property_0_is_inaccessible: { code: 2341, category: DiagnosticCategory.Error, key: "Property '{0}' is inaccessible." }, + Property_0_is_private_and_only_accessible_within_class_1: { code: 2341, category: DiagnosticCategory.Error, key: "Property '{0}' is private and only accessible within class '{1}'." }, An_index_expression_argument_must_be_of_type_string_number_or_any: { code: 2342, category: DiagnosticCategory.Error, key: "An index expression argument must be of type 'string', 'number', or 'any'." }, Type_0_does_not_satisfy_the_constraint_1_Colon: { code: 2343, category: DiagnosticCategory.Error, key: "Type '{0}' does not satisfy the constraint '{1}':" }, Type_0_does_not_satisfy_the_constraint_1: { code: 2344, category: DiagnosticCategory.Error, key: "Type '{0}' does not satisfy the constraint '{1}'." }, @@ -256,8 +256,10 @@ module ts { Import_declaration_conflicts_with_local_declaration_of_0: { code: 2440, category: DiagnosticCategory.Error, key: "Import declaration conflicts with local declaration of '{0}'" }, Duplicate_identifier_0_Compiler_reserves_name_1_in_top_level_scope_of_an_external_module: { code: 2441, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'. Compiler reserves name '{1}' in top level scope of an external module." }, Types_have_separate_declarations_of_a_private_property_0: { code: 2442, category: DiagnosticCategory.Error, key: "Types have separate declarations of a private property '{0}'." }, - Property_0_is_protected_but_type_1_is_not_derived_from_type_2: { code: 2443, category: DiagnosticCategory.Error, key: "Property '{0}' is protected but type '{1}' is not derived from type '{2}'." }, + Property_0_is_protected_but_type_1_is_not_a_class_derived_from_2: { code: 2443, category: DiagnosticCategory.Error, key: "Property '{0}' is protected but type '{1}' is not a class derived from '{2}'." }, Property_0_is_protected_in_type_1_but_public_in_type_2: { code: 2444, category: DiagnosticCategory.Error, key: "Property '{0}' is protected in type '{1}' but public in type '{2}'." }, + Property_0_is_protected_and_only_accessible_within_class_1_and_its_subclasses: { code: 2445, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible within class '{1}' and its subclasses." }, + Property_0_is_protected_and_only_accessible_through_an_instance_of_class_1: { code: 2446, category: DiagnosticCategory.Error, key: "Property '{0}' is protected and only accessible through an instance of class '{1}'." }, 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_name_1_from_private_module_2: { code: 4001, category: DiagnosticCategory.Error, key: "Type parameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." }, 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}'." }, diff --git a/src/compiler/diagnosticMessages.json b/src/compiler/diagnosticMessages.json index ba2c87180c92c..0480cd3000c26 100644 --- a/src/compiler/diagnosticMessages.json +++ b/src/compiler/diagnosticMessages.json @@ -608,7 +608,7 @@ "category": "Error", "code": 2340 }, - "Property '{0}' is inaccessible.": { + "Property '{0}' is private and only accessible within class '{1}'.": { "category": "Error", "code": 2341 }, @@ -1016,7 +1016,7 @@ "category": "Error", "code": 2442 }, - "Property '{0}' is protected but type '{1}' is not a class derived from type '{2}'.": { + "Property '{0}' is protected but type '{1}' is not a class derived from '{2}'.": { "category": "Error", "code": 2443 }, @@ -1024,6 +1024,14 @@ "category": "Error", "code": 2444 }, + "Property '{0}' is protected and only accessible within class '{1}' and its subclasses.": { + "category": "Error", + "code": 2445 + }, + "Property '{0}' is protected and only accessible through an instance of class '{1}'.": { + "category": "Error", + "code": 2446 + }, "Import declaration '{0}' is using private name '{1}'.": { "category": "Error", From ddfe28db66bdd41f9adb6d344e9794d9816e5e5e Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 19 Sep 2014 06:37:55 -0700 Subject: [PATCH 4/5] Accepting new baselines --- ...unctionUsingClassPrivateStatics.errors.txt | 4 +- .../classPropertyAsPrivate.errors.txt | 32 +++++++------- .../classWithPrivateProperty.errors.txt | 32 +++++++------- .../reference/cloduleStaticMembers.errors.txt | 4 +- .../constructorParameterProperties.errors.txt | 8 ++-- ...vateStaticShadowingPublicStatic.errors.txt | 16 +++---- .../errorSuperPropertyAccess.errors.txt | 12 ++--- ...faceExtendingClassWithPrivates2.errors.txt | 4 +- ...rfaceExtendingClassWithPrivates.errors.txt | 4 +- ...faceExtendingClassWithPrivates2.errors.txt | 8 ++-- ...erFunctionsWithPrivateOverloads.errors.txt | 16 +++---- ...tionsWithPublicPrivateOverloads.errors.txt | 8 ++-- ...InterfacesWithInheritedPrivates.errors.txt | 4 +- ...nterfacesWithInheritedPrivates2.errors.txt | 8 ++-- .../privateAccessInSubclass1.errors.txt | 4 +- ...vateInstanceMemberAccessibility.errors.txt | 4 +- ...rivateStaticMemberAccessibility.errors.txt | 8 ++-- ...ateStaticNotAccessibleInClodule.errors.txt | 4 +- ...teStaticNotAccessibleInClodule2.errors.txt | 4 +- .../reference/privateVisibility.errors.txt | 12 ++--- .../propertyAccessibility1.errors.txt | 4 +- .../propertyAccessibility2.errors.txt | 4 +- .../reference/protectedMembers.errors.txt | 44 +++++++++---------- .../reference/superPropertyAccess.errors.txt | 4 +- 24 files changed, 126 insertions(+), 126 deletions(-) diff --git a/tests/baselines/reference/ClassAndModuleThatMergeWithModulesExportedStaticFunctionUsingClassPrivateStatics.errors.txt b/tests/baselines/reference/ClassAndModuleThatMergeWithModulesExportedStaticFunctionUsingClassPrivateStatics.errors.txt index 6121bba66fb23..3feee7069d000 100644 --- a/tests/baselines/reference/ClassAndModuleThatMergeWithModulesExportedStaticFunctionUsingClassPrivateStatics.errors.txt +++ b/tests/baselines/reference/ClassAndModuleThatMergeWithModulesExportedStaticFunctionUsingClassPrivateStatics.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithModulesExportedStaticFunctionUsingClassPrivateStatics.ts(11,16): error TS2341: Property 'clodule.sfn' is inaccessible. +tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithModulesExportedStaticFunctionUsingClassPrivateStatics.ts(11,16): error TS2341: Property 'sfn' is private and only accessible within class 'clodule'. ==== tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMergeWithModulesExportedStaticFunctionUsingClassPrivateStatics.ts (1 errors) ==== @@ -14,7 +14,7 @@ tests/cases/conformance/internalModules/DeclarationMerging/ClassAndModuleThatMer export function fn(x: T, y: T): number { return clodule.sfn('a'); ~~~~~~~~~~~ -!!! error TS2341: Property 'clodule.sfn' is inaccessible. +!!! error TS2341: Property 'sfn' is private and only accessible within class 'clodule'. } } diff --git a/tests/baselines/reference/classPropertyAsPrivate.errors.txt b/tests/baselines/reference/classPropertyAsPrivate.errors.txt index 1ba10c61bd684..a5fdffe091a43 100644 --- a/tests/baselines/reference/classPropertyAsPrivate.errors.txt +++ b/tests/baselines/reference/classPropertyAsPrivate.errors.txt @@ -2,14 +2,14 @@ tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts( tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(4,17): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(8,24): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(9,24): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. -tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(15,1): error TS2341: Property 'C.x' is inaccessible. -tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(16,1): error TS2341: Property 'C.y' is inaccessible. -tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(17,1): error TS2341: Property 'C.y' is inaccessible. -tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(18,1): error TS2341: Property 'C.foo' is inaccessible. -tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(20,1): error TS2341: Property 'C.a' is inaccessible. -tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(21,1): error TS2341: Property 'C.b' is inaccessible. -tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(22,1): error TS2341: Property 'C.b' is inaccessible. -tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(23,1): error TS2341: Property 'C.foo' is inaccessible. +tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(15,1): error TS2341: Property 'x' is private and only accessible within class 'C'. +tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(16,1): error TS2341: Property 'y' is private and only accessible within class 'C'. +tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(17,1): error TS2341: Property 'y' is private and only accessible within class 'C'. +tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(18,1): error TS2341: Property 'foo' is private and only accessible within class 'C'. +tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(20,1): error TS2341: Property 'a' is private and only accessible within class 'C'. +tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(21,1): error TS2341: Property 'b' is private and only accessible within class 'C'. +tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(22,1): error TS2341: Property 'b' is private and only accessible within class 'C'. +tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts(23,1): error TS2341: Property 'foo' is private and only accessible within class 'C'. ==== tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts (12 errors) ==== @@ -37,26 +37,26 @@ tests/cases/conformance/classes/members/accessibility/classPropertyAsPrivate.ts( // all errors c.x; ~~~ -!!! error TS2341: Property 'C.x' is inaccessible. +!!! error TS2341: Property 'x' is private and only accessible within class 'C'. c.y; ~~~ -!!! error TS2341: Property 'C.y' is inaccessible. +!!! error TS2341: Property 'y' is private and only accessible within class 'C'. c.y = 1; ~~~ -!!! error TS2341: Property 'C.y' is inaccessible. +!!! error TS2341: Property 'y' is private and only accessible within class 'C'. c.foo(); ~~~~~ -!!! error TS2341: Property 'C.foo' is inaccessible. +!!! error TS2341: Property 'foo' is private and only accessible within class 'C'. C.a; ~~~ -!!! error TS2341: Property 'C.a' is inaccessible. +!!! error TS2341: Property 'a' is private and only accessible within class 'C'. C.b(); ~~~ -!!! error TS2341: Property 'C.b' is inaccessible. +!!! error TS2341: Property 'b' is private and only accessible within class 'C'. C.b = 1; ~~~ -!!! error TS2341: Property 'C.b' is inaccessible. +!!! error TS2341: Property 'b' is private and only accessible within class 'C'. C.foo(); ~~~~~ -!!! error TS2341: Property 'C.foo' is inaccessible. \ No newline at end of file +!!! error TS2341: Property 'foo' is private and only accessible within class 'C'. \ No newline at end of file diff --git a/tests/baselines/reference/classWithPrivateProperty.errors.txt b/tests/baselines/reference/classWithPrivateProperty.errors.txt index 54d960a412a16..93a94e2107582 100644 --- a/tests/baselines/reference/classWithPrivateProperty.errors.txt +++ b/tests/baselines/reference/classWithPrivateProperty.errors.txt @@ -1,11 +1,11 @@ -tests/cases/conformance/types/members/classWithPrivateProperty.ts(15,18): error TS2341: Property 'C.x' is inaccessible. -tests/cases/conformance/types/members/classWithPrivateProperty.ts(16,18): error TS2341: Property 'C.a' is inaccessible. -tests/cases/conformance/types/members/classWithPrivateProperty.ts(17,18): error TS2341: Property 'C.b' is inaccessible. -tests/cases/conformance/types/members/classWithPrivateProperty.ts(18,18): error TS2341: Property 'C.c' is inaccessible. -tests/cases/conformance/types/members/classWithPrivateProperty.ts(19,18): error TS2341: Property 'C.d' is inaccessible. -tests/cases/conformance/types/members/classWithPrivateProperty.ts(20,18): error TS2341: Property 'C.e' is inaccessible. -tests/cases/conformance/types/members/classWithPrivateProperty.ts(21,18): error TS2341: Property 'C.f' is inaccessible. -tests/cases/conformance/types/members/classWithPrivateProperty.ts(22,18): error TS2341: Property 'C.g' is inaccessible. +tests/cases/conformance/types/members/classWithPrivateProperty.ts(15,18): error TS2341: Property 'x' is private and only accessible within class 'C'. +tests/cases/conformance/types/members/classWithPrivateProperty.ts(16,18): error TS2341: Property 'a' is private and only accessible within class 'C'. +tests/cases/conformance/types/members/classWithPrivateProperty.ts(17,18): error TS2341: Property 'b' is private and only accessible within class 'C'. +tests/cases/conformance/types/members/classWithPrivateProperty.ts(18,18): error TS2341: Property 'c' is private and only accessible within class 'C'. +tests/cases/conformance/types/members/classWithPrivateProperty.ts(19,18): error TS2341: Property 'd' is private and only accessible within class 'C'. +tests/cases/conformance/types/members/classWithPrivateProperty.ts(20,18): error TS2341: Property 'e' is private and only accessible within class 'C'. +tests/cases/conformance/types/members/classWithPrivateProperty.ts(21,18): error TS2341: Property 'f' is private and only accessible within class 'C'. +tests/cases/conformance/types/members/classWithPrivateProperty.ts(22,18): error TS2341: Property 'g' is private and only accessible within class 'C'. ==== tests/cases/conformance/types/members/classWithPrivateProperty.ts (8 errors) ==== @@ -25,25 +25,25 @@ tests/cases/conformance/types/members/classWithPrivateProperty.ts(22,18): error var c = new C(); var r1: string = c.x; ~~~ -!!! error TS2341: Property 'C.x' is inaccessible. +!!! error TS2341: Property 'x' is private and only accessible within class 'C'. var r2: string = c.a; ~~~ -!!! error TS2341: Property 'C.a' is inaccessible. +!!! error TS2341: Property 'a' is private and only accessible within class 'C'. var r3: string = c.b; ~~~ -!!! error TS2341: Property 'C.b' is inaccessible. +!!! error TS2341: Property 'b' is private and only accessible within class 'C'. var r4: string = c.c(); ~~~ -!!! error TS2341: Property 'C.c' is inaccessible. +!!! error TS2341: Property 'c' is private and only accessible within class 'C'. var r5: string = c.d(); ~~~ -!!! error TS2341: Property 'C.d' is inaccessible. +!!! error TS2341: Property 'd' is private and only accessible within class 'C'. var r6: string = C.e; ~~~ -!!! error TS2341: Property 'C.e' is inaccessible. +!!! error TS2341: Property 'e' is private and only accessible within class 'C'. var r7: string = C.f(); ~~~ -!!! error TS2341: Property 'C.f' is inaccessible. +!!! error TS2341: Property 'f' is private and only accessible within class 'C'. var r8: string = C.g(); ~~~ -!!! error TS2341: Property 'C.g' is inaccessible. \ No newline at end of file +!!! error TS2341: Property 'g' is private and only accessible within class 'C'. \ No newline at end of file diff --git a/tests/baselines/reference/cloduleStaticMembers.errors.txt b/tests/baselines/reference/cloduleStaticMembers.errors.txt index 5b396c3be35da..914fea72424b3 100644 --- a/tests/baselines/reference/cloduleStaticMembers.errors.txt +++ b/tests/baselines/reference/cloduleStaticMembers.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/cloduleStaticMembers.ts(6,13): error TS2341: Property 'Clod.x' is inaccessible. +tests/cases/compiler/cloduleStaticMembers.ts(6,13): error TS2341: Property 'x' is private and only accessible within class 'Clod'. tests/cases/compiler/cloduleStaticMembers.ts(7,13): error TS2304: Cannot find name 'x'. tests/cases/compiler/cloduleStaticMembers.ts(10,13): error TS2304: Cannot find name 'y'. @@ -11,7 +11,7 @@ tests/cases/compiler/cloduleStaticMembers.ts(10,13): error TS2304: Cannot find n module Clod { var p = Clod.x; ~~~~~~ -!!! error TS2341: Property 'Clod.x' is inaccessible. +!!! error TS2341: Property 'x' is private and only accessible within class 'Clod'. var q = x; ~ !!! error TS2304: Cannot find name 'x'. diff --git a/tests/baselines/reference/constructorParameterProperties.errors.txt b/tests/baselines/reference/constructorParameterProperties.errors.txt index ed41bec0e4a96..63018d57024eb 100644 --- a/tests/baselines/reference/constructorParameterProperties.errors.txt +++ b/tests/baselines/reference/constructorParameterProperties.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts(8,10): error TS2341: Property 'C.x' is inaccessible. -tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts(17,10): error TS2341: Property 'D.x' is inaccessible. +tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts(8,10): error TS2341: Property 'x' is private and only accessible within class 'C'. +tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts(17,10): error TS2341: Property 'x' is private and only accessible within class 'D'. tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts(18,12): error TS2339: Property 'a' does not exist on type 'D'. @@ -13,7 +13,7 @@ tests/cases/conformance/classes/constructorDeclarations/constructorParameters/co var r = c.y; var r2 = c.x; // error ~~~ -!!! error TS2341: Property 'C.x' is inaccessible. +!!! error TS2341: Property 'x' is private and only accessible within class 'C'. class D { y: T; @@ -24,7 +24,7 @@ tests/cases/conformance/classes/constructorDeclarations/constructorParameters/co var r = d.y; var r2 = d.x; // error ~~~ -!!! error TS2341: Property 'D.x' is inaccessible. +!!! error TS2341: Property 'x' is private and only accessible within class 'D'. var r3 = d.a; // error ~ !!! error TS2339: Property 'a' does not exist on type 'D'. \ No newline at end of file diff --git a/tests/baselines/reference/derivedClassWithPrivateStaticShadowingPublicStatic.errors.txt b/tests/baselines/reference/derivedClassWithPrivateStaticShadowingPublicStatic.errors.txt index 44e73278091ad..a792c8ebff0fd 100644 --- a/tests/baselines/reference/derivedClassWithPrivateStaticShadowingPublicStatic.errors.txt +++ b/tests/baselines/reference/derivedClassWithPrivateStaticShadowingPublicStatic.errors.txt @@ -4,10 +4,10 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWit tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic.ts(20,24): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic.ts(13,7): error TS2418: Class static side 'typeof Derived' incorrectly extends base class static side 'typeof Base': Property 'x' is private in type 'typeof Derived' but not in type 'typeof Base'. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic.ts(24,10): error TS2341: Property 'Derived.x' is inaccessible. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic.ts(27,10): error TS2341: Property 'Derived.fn' is inaccessible. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic.ts(32,10): error TS2341: Property 'Derived.a' is inaccessible. -tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic.ts(33,1): error TS2341: Property 'Derived.a' is inaccessible. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic.ts(24,10): error TS2341: Property 'x' is private and only accessible within class 'Derived'. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic.ts(27,10): error TS2341: Property 'fn' is private and only accessible within class 'Derived'. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic.ts(32,10): error TS2341: Property 'a' is private and only accessible within class 'Derived'. +tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic.ts(33,1): error TS2341: Property 'a' is private and only accessible within class 'Derived'. ==== tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWithPrivateStaticShadowingPublicStatic.ts (9 errors) ==== @@ -47,19 +47,19 @@ tests/cases/conformance/classes/members/inheritanceAndOverriding/derivedClassWit var r = Base.x; // ok var r2 = Derived.x; // error ~~~~~~~~~ -!!! error TS2341: Property 'Derived.x' is inaccessible. +!!! error TS2341: Property 'x' is private and only accessible within class 'Derived'. var r3 = Base.fn(); // ok var r4 = Derived.fn(); // error ~~~~~~~~~~ -!!! error TS2341: Property 'Derived.fn' is inaccessible. +!!! error TS2341: Property 'fn' is private and only accessible within class 'Derived'. var r5 = Base.a; // ok Base.a = 2; // ok var r6 = Derived.a; // error ~~~~~~~~~ -!!! error TS2341: Property 'Derived.a' is inaccessible. +!!! error TS2341: Property 'a' is private and only accessible within class 'Derived'. Derived.a = 2; // error ~~~~~~~~~ -!!! error TS2341: Property 'Derived.a' is inaccessible. \ No newline at end of file +!!! error TS2341: Property 'a' is private and only accessible within class 'Derived'. \ No newline at end of file diff --git a/tests/baselines/reference/errorSuperPropertyAccess.errors.txt b/tests/baselines/reference/errorSuperPropertyAccess.errors.txt index 685d53653465e..e192e99b87f78 100644 --- a/tests/baselines/reference/errorSuperPropertyAccess.errors.txt +++ b/tests/baselines/reference/errorSuperPropertyAccess.errors.txt @@ -27,13 +27,13 @@ tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(99,19): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(109,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(110,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword -tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(111,9): error TS2341: Property 'SomeBase.privateStaticFunc' is inaccessible. +tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(111,9): error TS2341: Property 'privateStaticFunc' is private and only accessible within class 'SomeBase'. tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(114,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(115,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword -tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(116,9): error TS2341: Property 'SomeBase.privateStaticFunc' is inaccessible. +tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(116,9): error TS2341: Property 'privateStaticFunc' is private and only accessible within class 'SomeBase'. tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(120,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(121,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword -tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(122,9): error TS2341: Property 'SomeBase.privateStaticFunc' is inaccessible. +tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(122,9): error TS2341: Property 'privateStaticFunc' is private and only accessible within class 'SomeBase'. tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(127,16): error TS2335: 'super' can only be referenced in a derived class. tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess.ts(127,30): error TS2335: 'super' can only be referenced in a derived class. @@ -205,7 +205,7 @@ tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess !!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword super.privateStaticFunc(); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2341: Property 'SomeBase.privateStaticFunc' is inaccessible. +!!! error TS2341: Property 'privateStaticFunc' is private and only accessible within class 'SomeBase'. } static get a() { ~ @@ -218,7 +218,7 @@ tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess !!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword super.privateStaticFunc(); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2341: Property 'SomeBase.privateStaticFunc' is inaccessible. +!!! error TS2341: Property 'privateStaticFunc' is private and only accessible within class 'SomeBase'. return ''; } static set a(n) { @@ -232,7 +232,7 @@ tests/cases/conformance/expressions/superPropertyAccess/errorSuperPropertyAccess !!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword super.privateStaticFunc(); ~~~~~~~~~~~~~~~~~~~~~~~ -!!! error TS2341: Property 'SomeBase.privateStaticFunc' is inaccessible. +!!! error TS2341: Property 'privateStaticFunc' is private and only accessible within class 'SomeBase'. } } diff --git a/tests/baselines/reference/implementingAnInterfaceExtendingClassWithPrivates2.errors.txt b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithPrivates2.errors.txt index a528bb6835b00..53fc5c54bee36 100644 --- a/tests/baselines/reference/implementingAnInterfaceExtendingClassWithPrivates2.errors.txt +++ b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithPrivates2.errors.txt @@ -16,7 +16,7 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInte Property 'z' is missing in type 'Bar3'. tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithPrivates2.ts(67,11): error TS2421: Class 'Bar' incorrectly implements interface 'I': Property 'y' is missing in type 'Bar'. -tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithPrivates2.ts(73,14): error TS2341: Property 'Foo.x' is inaccessible. +tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithPrivates2.ts(73,14): error TS2341: Property 'x' is private and only accessible within class 'Foo'. tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithPrivates2.ts(74,16): error TS2339: Property 'y' does not exist on type 'Bar'. tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithPrivates2.ts(76,11): error TS2416: Class 'Bar2' incorrectly extends base class 'Foo': Property 'x' is private in type 'Foo' but not in type 'Bar2'. @@ -130,7 +130,7 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInte var r1 = b.z; var r2 = b.x; // error ~~~ -!!! error TS2341: Property 'Foo.x' is inaccessible. +!!! error TS2341: Property 'x' is private and only accessible within class 'Foo'. var r3 = b.y; // error ~ !!! error TS2339: Property 'y' does not exist on type 'Bar'. diff --git a/tests/baselines/reference/interfaceExtendingClassWithPrivates.errors.txt b/tests/baselines/reference/interfaceExtendingClassWithPrivates.errors.txt index c1fb202e0c099..93d8b7cfa57e3 100644 --- a/tests/baselines/reference/interfaceExtendingClassWithPrivates.errors.txt +++ b/tests/baselines/reference/interfaceExtendingClassWithPrivates.errors.txt @@ -1,6 +1,6 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithPrivates.ts(5,11): error TS2429: Interface 'I' incorrectly extends interface 'Foo': Property 'x' is private in type 'Foo' but not in type 'I'. -tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithPrivates.ts(15,10): error TS2341: Property 'Foo.x' is inaccessible. +tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithPrivates.ts(15,10): error TS2341: Property 'x' is private and only accessible within class 'Foo'. ==== tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithPrivates.ts (2 errors) ==== @@ -23,4 +23,4 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtending var r = i.y; var r2 = i.x; // error ~~~ -!!! error TS2341: Property 'Foo.x' is inaccessible. \ No newline at end of file +!!! error TS2341: Property 'x' is private and only accessible within class 'Foo'. \ No newline at end of file diff --git a/tests/baselines/reference/interfaceExtendingClassWithPrivates2.errors.txt b/tests/baselines/reference/interfaceExtendingClassWithPrivates2.errors.txt index e1f511827db46..f17a1ef348514 100644 --- a/tests/baselines/reference/interfaceExtendingClassWithPrivates2.errors.txt +++ b/tests/baselines/reference/interfaceExtendingClassWithPrivates2.errors.txt @@ -4,8 +4,8 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtending Property 'x' is private in type 'Bar' but not in type 'I4'. tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithPrivates2.ts(12,11): error TS2429: Interface 'I4' incorrectly extends interface 'Foo': Property 'x' is private in type 'Foo' but not in type 'I4'. -tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithPrivates2.ts(26,10): error TS2341: Property 'Foo.x' is inaccessible. -tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithPrivates2.ts(27,10): error TS2341: Property 'Baz.y' is inaccessible. +tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithPrivates2.ts(26,10): error TS2341: Property 'x' is private and only accessible within class 'Foo'. +tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithPrivates2.ts(27,10): error TS2341: Property 'y' is private and only accessible within class 'Baz'. ==== tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithPrivates2.ts (5 errors) ==== @@ -45,7 +45,7 @@ tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtending var r: string = i.z; var r2 = i.x; // error ~~~ -!!! error TS2341: Property 'Foo.x' is inaccessible. +!!! error TS2341: Property 'x' is private and only accessible within class 'Foo'. var r3 = i.y; // error ~~~ -!!! error TS2341: Property 'Baz.y' is inaccessible. \ No newline at end of file +!!! error TS2341: Property 'y' is private and only accessible within class 'Baz'. \ No newline at end of file diff --git a/tests/baselines/reference/memberFunctionsWithPrivateOverloads.errors.txt b/tests/baselines/reference/memberFunctionsWithPrivateOverloads.errors.txt index 45b1569dbfbe8..d6c3d4a659c93 100644 --- a/tests/baselines/reference/memberFunctionsWithPrivateOverloads.errors.txt +++ b/tests/baselines/reference/memberFunctionsWithPrivateOverloads.errors.txt @@ -1,7 +1,7 @@ -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPrivateOverloads.ts(43,9): error TS2341: Property 'C.foo' is inaccessible. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPrivateOverloads.ts(46,10): error TS2341: Property 'D.foo' is inaccessible. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPrivateOverloads.ts(48,10): error TS2341: Property 'C.foo' is inaccessible. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPrivateOverloads.ts(49,10): error TS2341: Property 'D.bar' is inaccessible. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPrivateOverloads.ts(43,9): error TS2341: Property 'foo' is private and only accessible within class 'C'. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPrivateOverloads.ts(46,10): error TS2341: Property 'foo' is private and only accessible within class 'D'. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPrivateOverloads.ts(48,10): error TS2341: Property 'foo' is private and only accessible within class 'C'. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPrivateOverloads.ts(49,10): error TS2341: Property 'bar' is private and only accessible within class 'D'. ==== tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPrivateOverloads.ts (4 errors) ==== @@ -49,16 +49,16 @@ tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclara var c: C; var r = c.foo(1); // error ~~~~~ -!!! error TS2341: Property 'C.foo' is inaccessible. +!!! error TS2341: Property 'foo' is private and only accessible within class 'C'. var d: D; var r2 = d.foo(2); // error ~~~~~ -!!! error TS2341: Property 'D.foo' is inaccessible. +!!! error TS2341: Property 'foo' is private and only accessible within class 'D'. var r3 = C.foo(1); // error ~~~~~ -!!! error TS2341: Property 'C.foo' is inaccessible. +!!! error TS2341: Property 'foo' is private and only accessible within class 'C'. var r4 = D.bar(''); // error ~~~~~ -!!! error TS2341: Property 'D.bar' is inaccessible. \ No newline at end of file +!!! error TS2341: Property 'bar' is private and only accessible within class 'D'. \ No newline at end of file diff --git a/tests/baselines/reference/memberFunctionsWithPublicPrivateOverloads.errors.txt b/tests/baselines/reference/memberFunctionsWithPublicPrivateOverloads.errors.txt index ed9160d3db376..95c12e4db040c 100644 --- a/tests/baselines/reference/memberFunctionsWithPublicPrivateOverloads.errors.txt +++ b/tests/baselines/reference/memberFunctionsWithPublicPrivateOverloads.errors.txt @@ -6,8 +6,8 @@ tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclara tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(27,12): error TS2385: Overload signatures must all be public, private or protected. tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(32,19): error TS2385: Overload signatures must all be public, private or protected. tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(36,19): error TS2385: Overload signatures must all be public, private or protected. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(42,9): error TS2341: Property 'C.foo' is inaccessible. -tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(45,10): error TS2341: Property 'D.foo' is inaccessible. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(42,9): error TS2341: Property 'foo' is private and only accessible within class 'C'. +tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts(45,10): error TS2341: Property 'foo' is private and only accessible within class 'D'. ==== tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclarations/memberFunctionsWithPublicPrivateOverloads.ts (10 errors) ==== @@ -70,9 +70,9 @@ tests/cases/conformance/classes/propertyMemberDeclarations/memberFunctionDeclara var c: C; var r = c.foo(1); // error ~~~~~ -!!! error TS2341: Property 'C.foo' is inaccessible. +!!! error TS2341: Property 'foo' is private and only accessible within class 'C'. var d: D; var r2 = d.foo(2); // error ~~~~~ -!!! error TS2341: Property 'D.foo' is inaccessible. \ No newline at end of file +!!! error TS2341: Property 'foo' is private and only accessible within class 'D'. \ No newline at end of file diff --git a/tests/baselines/reference/mergedInterfacesWithInheritedPrivates.errors.txt b/tests/baselines/reference/mergedInterfacesWithInheritedPrivates.errors.txt index 18ebd68b64059..f1ee1f383bfa3 100644 --- a/tests/baselines/reference/mergedInterfacesWithInheritedPrivates.errors.txt +++ b/tests/baselines/reference/mergedInterfacesWithInheritedPrivates.errors.txt @@ -2,7 +2,7 @@ tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithInheri Types have separate declarations of a private property 'x'. tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates.ts(19,7): error TS2421: Class 'E' incorrectly implements interface 'A': Property 'x' is private in type 'A' but not in type 'E'. -tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates.ts(26,9): error TS2341: Property 'C.x' is inaccessible. +tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates.ts(26,9): error TS2341: Property 'x' is private and only accessible within class 'C'. ==== tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates.ts (3 errors) ==== @@ -39,4 +39,4 @@ tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithInheri var a: A; var r = a.x; // error ~~~ -!!! error TS2341: Property 'C.x' is inaccessible. \ No newline at end of file +!!! error TS2341: Property 'x' is private and only accessible within class 'C'. \ No newline at end of file diff --git a/tests/baselines/reference/mergedInterfacesWithInheritedPrivates2.errors.txt b/tests/baselines/reference/mergedInterfacesWithInheritedPrivates2.errors.txt index b4ff202d0ff78..0ca3b4c3aa2a6 100644 --- a/tests/baselines/reference/mergedInterfacesWithInheritedPrivates2.errors.txt +++ b/tests/baselines/reference/mergedInterfacesWithInheritedPrivates2.errors.txt @@ -4,8 +4,8 @@ tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithInheri Property 'w' is private in type 'C2' but not in type 'E'. tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates2.ts(23,7): error TS2421: Class 'E' incorrectly implements interface 'A': Property 'x' is missing in type 'E'. -tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates2.ts(30,9): error TS2341: Property 'C.x' is inaccessible. -tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates2.ts(31,10): error TS2341: Property 'C2.w' is inaccessible. +tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates2.ts(30,9): error TS2341: Property 'x' is private and only accessible within class 'C'. +tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates2.ts(31,10): error TS2341: Property 'w' is private and only accessible within class 'C2'. ==== tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithInheritedPrivates2.ts (5 errors) ==== @@ -49,7 +49,7 @@ tests/cases/conformance/interfaces/declarationMerging/mergedInterfacesWithInheri var a: A; var r = a.x; // error ~~~ -!!! error TS2341: Property 'C.x' is inaccessible. +!!! error TS2341: Property 'x' is private and only accessible within class 'C'. var r2 = a.w; // error ~~~ -!!! error TS2341: Property 'C2.w' is inaccessible. \ No newline at end of file +!!! error TS2341: Property 'w' is private and only accessible within class 'C2'. \ No newline at end of file diff --git a/tests/baselines/reference/privateAccessInSubclass1.errors.txt b/tests/baselines/reference/privateAccessInSubclass1.errors.txt index 471c938b644ef..5ffb876a72805 100644 --- a/tests/baselines/reference/privateAccessInSubclass1.errors.txt +++ b/tests/baselines/reference/privateAccessInSubclass1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/privateAccessInSubclass1.ts(7,5): error TS2341: Property 'Base.options' is inaccessible. +tests/cases/compiler/privateAccessInSubclass1.ts(7,5): error TS2341: Property 'options' is private and only accessible within class 'Base'. ==== tests/cases/compiler/privateAccessInSubclass1.ts (1 errors) ==== @@ -10,6 +10,6 @@ tests/cases/compiler/privateAccessInSubclass1.ts(7,5): error TS2341: Property 'B myMethod() { this.options; ~~~~~~~~~~~~ -!!! error TS2341: Property 'Base.options' is inaccessible. +!!! error TS2341: Property 'options' is private and only accessible within class 'Base'. } } \ No newline at end of file diff --git a/tests/baselines/reference/privateInstanceMemberAccessibility.errors.txt b/tests/baselines/reference/privateInstanceMemberAccessibility.errors.txt index 3a3609d0bafed..1c173ff0fb18d 100644 --- a/tests/baselines/reference/privateInstanceMemberAccessibility.errors.txt +++ b/tests/baselines/reference/privateInstanceMemberAccessibility.errors.txt @@ -3,7 +3,7 @@ tests/cases/conformance/classes/members/accessibility/privateInstanceMemberAcces tests/cases/conformance/classes/members/accessibility/privateInstanceMemberAccessibility.ts(6,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword tests/cases/conformance/classes/members/accessibility/privateInstanceMemberAccessibility.ts(8,22): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword tests/cases/conformance/classes/members/accessibility/privateInstanceMemberAccessibility.ts(10,21): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword -tests/cases/conformance/classes/members/accessibility/privateInstanceMemberAccessibility.ts(12,8): error TS2341: Property 'Base.foo' is inaccessible. +tests/cases/conformance/classes/members/accessibility/privateInstanceMemberAccessibility.ts(12,8): error TS2341: Property 'foo' is private and only accessible within class 'Base'. ==== tests/cases/conformance/classes/members/accessibility/privateInstanceMemberAccessibility.ts (6 errors) ==== @@ -30,5 +30,5 @@ tests/cases/conformance/classes/members/accessibility/privateInstanceMemberAcces ~~~~ !!! error TS1110: Type expected. ~~~~~~~~ -!!! error TS2341: Property 'Base.foo' is inaccessible. +!!! error TS2341: Property 'foo' is private and only accessible within class 'Base'. } \ No newline at end of file diff --git a/tests/baselines/reference/privateStaticMemberAccessibility.errors.txt b/tests/baselines/reference/privateStaticMemberAccessibility.errors.txt index a2c2d9971bd34..4ec16f020454c 100644 --- a/tests/baselines/reference/privateStaticMemberAccessibility.errors.txt +++ b/tests/baselines/reference/privateStaticMemberAccessibility.errors.txt @@ -1,5 +1,5 @@ -tests/cases/conformance/classes/members/accessibility/privateStaticMemberAccessibility.ts(6,18): error TS2341: Property 'Base.foo' is inaccessible. -tests/cases/conformance/classes/members/accessibility/privateStaticMemberAccessibility.ts(7,18): error TS2341: Property 'Base.foo' is inaccessible. +tests/cases/conformance/classes/members/accessibility/privateStaticMemberAccessibility.ts(6,18): error TS2341: Property 'foo' is private and only accessible within class 'Base'. +tests/cases/conformance/classes/members/accessibility/privateStaticMemberAccessibility.ts(7,18): error TS2341: Property 'foo' is private and only accessible within class 'Base'. ==== tests/cases/conformance/classes/members/accessibility/privateStaticMemberAccessibility.ts (2 errors) ==== @@ -10,8 +10,8 @@ tests/cases/conformance/classes/members/accessibility/privateStaticMemberAccessi class Derived extends Base { static bar = Base.foo; // error ~~~~~~~~ -!!! error TS2341: Property 'Base.foo' is inaccessible. +!!! error TS2341: Property 'foo' is private and only accessible within class 'Base'. bing = () => Base.foo; // error ~~~~~~~~ -!!! error TS2341: Property 'Base.foo' is inaccessible. +!!! error TS2341: Property 'foo' is private and only accessible within class 'Base'. } \ No newline at end of file diff --git a/tests/baselines/reference/privateStaticNotAccessibleInClodule.errors.txt b/tests/baselines/reference/privateStaticNotAccessibleInClodule.errors.txt index 48da525b55a71..a5834b6cd0fd7 100644 --- a/tests/baselines/reference/privateStaticNotAccessibleInClodule.errors.txt +++ b/tests/baselines/reference/privateStaticNotAccessibleInClodule.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/members/accessibility/privateStaticNotAccessibleInClodule.ts(9,20): error TS2341: Property 'C.bar' is inaccessible. +tests/cases/conformance/classes/members/accessibility/privateStaticNotAccessibleInClodule.ts(9,20): error TS2341: Property 'bar' is private and only accessible within class 'C'. ==== tests/cases/conformance/classes/members/accessibility/privateStaticNotAccessibleInClodule.ts (1 errors) ==== @@ -12,5 +12,5 @@ tests/cases/conformance/classes/members/accessibility/privateStaticNotAccessible module C { export var y = C.bar; // error ~~~~~ -!!! error TS2341: Property 'C.bar' is inaccessible. +!!! error TS2341: Property 'bar' is private and only accessible within class 'C'. } \ No newline at end of file diff --git a/tests/baselines/reference/privateStaticNotAccessibleInClodule2.errors.txt b/tests/baselines/reference/privateStaticNotAccessibleInClodule2.errors.txt index 3c58189147864..950649ee4b224 100644 --- a/tests/baselines/reference/privateStaticNotAccessibleInClodule2.errors.txt +++ b/tests/baselines/reference/privateStaticNotAccessibleInClodule2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/conformance/classes/members/accessibility/privateStaticNotAccessibleInClodule2.ts(13,20): error TS2341: Property 'C.bar' is inaccessible. +tests/cases/conformance/classes/members/accessibility/privateStaticNotAccessibleInClodule2.ts(13,20): error TS2341: Property 'bar' is private and only accessible within class 'C'. ==== tests/cases/conformance/classes/members/accessibility/privateStaticNotAccessibleInClodule2.ts (1 errors) ==== @@ -16,5 +16,5 @@ tests/cases/conformance/classes/members/accessibility/privateStaticNotAccessible module D { export var y = D.bar; // error ~~~~~ -!!! error TS2341: Property 'C.bar' is inaccessible. +!!! error TS2341: Property 'bar' is private and only accessible within class 'C'. } \ No newline at end of file diff --git a/tests/baselines/reference/privateVisibility.errors.txt b/tests/baselines/reference/privateVisibility.errors.txt index 9c2283383581a..88784706f4381 100644 --- a/tests/baselines/reference/privateVisibility.errors.txt +++ b/tests/baselines/reference/privateVisibility.errors.txt @@ -1,6 +1,6 @@ -tests/cases/compiler/privateVisibility.ts(9,1): error TS2341: Property 'Foo.privMeth' is inaccessible. -tests/cases/compiler/privateVisibility.ts(10,1): error TS2341: Property 'Foo.privProp' is inaccessible. -tests/cases/compiler/privateVisibility.ts(24,1): error TS2341: Property 'M.C.priv' is inaccessible. +tests/cases/compiler/privateVisibility.ts(9,1): error TS2341: Property 'privMeth' is private and only accessible within class 'Foo'. +tests/cases/compiler/privateVisibility.ts(10,1): error TS2341: Property 'privProp' is private and only accessible within class 'Foo'. +tests/cases/compiler/privateVisibility.ts(24,1): error TS2341: Property 'priv' is private and only accessible within class 'C'. ==== tests/cases/compiler/privateVisibility.ts (3 errors) ==== @@ -14,10 +14,10 @@ tests/cases/compiler/privateVisibility.ts(24,1): error TS2341: Property 'M.C.pri var f = new Foo(); f.privMeth(); // should not work ~~~~~~~~~~ -!!! error TS2341: Property 'Foo.privMeth' is inaccessible. +!!! error TS2341: Property 'privMeth' is private and only accessible within class 'Foo'. f.privProp; // should not work ~~~~~~~~~~ -!!! error TS2341: Property 'Foo.privProp' is inaccessible. +!!! error TS2341: Property 'privProp' is private and only accessible within class 'Foo'. f.pubMeth(); // should work f.pubProp; // should work @@ -33,6 +33,6 @@ tests/cases/compiler/privateVisibility.ts(24,1): error TS2341: Property 'M.C.pri c.pub; // should work c.priv; // should not work ~~~~~~ -!!! error TS2341: Property 'M.C.priv' is inaccessible. +!!! error TS2341: Property 'priv' is private and only accessible within class 'C'. \ No newline at end of file diff --git a/tests/baselines/reference/propertyAccessibility1.errors.txt b/tests/baselines/reference/propertyAccessibility1.errors.txt index a26dd0d93718c..2caf251b2a590 100644 --- a/tests/baselines/reference/propertyAccessibility1.errors.txt +++ b/tests/baselines/reference/propertyAccessibility1.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/propertyAccessibility1.ts(5,1): error TS2341: Property 'Foo.privProp' is inaccessible. +tests/cases/compiler/propertyAccessibility1.ts(5,1): error TS2341: Property 'privProp' is private and only accessible within class 'Foo'. ==== tests/cases/compiler/propertyAccessibility1.ts (1 errors) ==== @@ -8,5 +8,5 @@ tests/cases/compiler/propertyAccessibility1.ts(5,1): error TS2341: Property 'Foo var f = new Foo(); f.privProp; ~~~~~~~~~~ -!!! error TS2341: Property 'Foo.privProp' is inaccessible. +!!! error TS2341: Property 'privProp' is private and only accessible within class 'Foo'. \ No newline at end of file diff --git a/tests/baselines/reference/propertyAccessibility2.errors.txt b/tests/baselines/reference/propertyAccessibility2.errors.txt index fba83b50a8b5c..7eb81d45ed44a 100644 --- a/tests/baselines/reference/propertyAccessibility2.errors.txt +++ b/tests/baselines/reference/propertyAccessibility2.errors.txt @@ -1,4 +1,4 @@ -tests/cases/compiler/propertyAccessibility2.ts(4,9): error TS2341: Property 'C.x' is inaccessible. +tests/cases/compiler/propertyAccessibility2.ts(4,9): error TS2341: Property 'x' is private and only accessible within class 'C'. ==== tests/cases/compiler/propertyAccessibility2.ts (1 errors) ==== @@ -7,5 +7,5 @@ tests/cases/compiler/propertyAccessibility2.ts(4,9): error TS2341: Property 'C.x } var c = C.x; ~~~ -!!! error TS2341: Property 'C.x' is inaccessible. +!!! error TS2341: Property 'x' is private and only accessible within class 'C'. \ No newline at end of file diff --git a/tests/baselines/reference/protectedMembers.errors.txt b/tests/baselines/reference/protectedMembers.errors.txt index 97a7a786231e5..ce9529a7f6726 100644 --- a/tests/baselines/reference/protectedMembers.errors.txt +++ b/tests/baselines/reference/protectedMembers.errors.txt @@ -1,16 +1,16 @@ tests/cases/compiler/protectedMembers.ts(86,5): error TS1089: 'protected' modifier cannot appear on a constructor declaration. -tests/cases/compiler/protectedMembers.ts(40,1): error TS2341: Property 'C1.x' is inaccessible. -tests/cases/compiler/protectedMembers.ts(41,1): error TS2341: Property 'C1.f' is inaccessible. -tests/cases/compiler/protectedMembers.ts(42,1): error TS2341: Property 'C1.sx' is inaccessible. -tests/cases/compiler/protectedMembers.ts(43,1): error TS2341: Property 'C1.sf' is inaccessible. -tests/cases/compiler/protectedMembers.ts(46,1): error TS2341: Property 'C1.x' is inaccessible. -tests/cases/compiler/protectedMembers.ts(47,1): error TS2341: Property 'C2.f' is inaccessible. -tests/cases/compiler/protectedMembers.ts(48,1): error TS2341: Property 'C1.sx' is inaccessible. -tests/cases/compiler/protectedMembers.ts(49,1): error TS2341: Property 'C2.sf' is inaccessible. -tests/cases/compiler/protectedMembers.ts(68,9): error TS2341: Property 'A.x' is inaccessible. -tests/cases/compiler/protectedMembers.ts(69,9): error TS2341: Property 'A.x' is inaccessible. +tests/cases/compiler/protectedMembers.ts(40,1): error TS2445: Property 'x' is protected and only accessible within class 'C1' and its subclasses. +tests/cases/compiler/protectedMembers.ts(41,1): error TS2445: Property 'f' is protected and only accessible within class 'C1' and its subclasses. +tests/cases/compiler/protectedMembers.ts(42,1): error TS2445: Property 'sx' is protected and only accessible within class 'C1' and its subclasses. +tests/cases/compiler/protectedMembers.ts(43,1): error TS2445: Property 'sf' is protected and only accessible within class 'C1' and its subclasses. +tests/cases/compiler/protectedMembers.ts(46,1): error TS2445: Property 'x' is protected and only accessible within class 'C1' and its subclasses. +tests/cases/compiler/protectedMembers.ts(47,1): error TS2445: Property 'f' is protected and only accessible within class 'C2' and its subclasses. +tests/cases/compiler/protectedMembers.ts(48,1): error TS2445: Property 'sx' is protected and only accessible within class 'C1' and its subclasses. +tests/cases/compiler/protectedMembers.ts(49,1): error TS2445: Property 'sf' is protected and only accessible within class 'C2' and its subclasses. +tests/cases/compiler/protectedMembers.ts(68,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'C'. +tests/cases/compiler/protectedMembers.ts(69,9): error TS2446: Property 'x' is protected and only accessible through an instance of class 'C'. tests/cases/compiler/protectedMembers.ts(98,1): error TS2322: Type 'B1' is not assignable to type 'A1': - Property 'x' is protected but type 'B1' is not derived from type 'A1'. + Property 'x' is protected but type 'B1' is not a class derived from 'A1'. tests/cases/compiler/protectedMembers.ts(99,1): error TS2322: Type 'A1' is not assignable to type 'B1': Property 'x' is protected in type 'A1' but public in type 'B1'. tests/cases/compiler/protectedMembers.ts(112,7): error TS2416: Class 'B3' incorrectly extends base class 'A3': @@ -59,30 +59,30 @@ tests/cases/compiler/protectedMembers.ts(112,7): error TS2416: Class 'B3' incorr // All of these should be errors c1.x; ~~~~ -!!! error TS2341: Property 'C1.x' is inaccessible. +!!! error TS2445: Property 'x' is protected and only accessible within class 'C1' and its subclasses. c1.f(); ~~~~ -!!! error TS2341: Property 'C1.f' is inaccessible. +!!! error TS2445: Property 'f' is protected and only accessible within class 'C1' and its subclasses. C1.sx; ~~~~~ -!!! error TS2341: Property 'C1.sx' is inaccessible. +!!! error TS2445: Property 'sx' is protected and only accessible within class 'C1' and its subclasses. C1.sf(); ~~~~~ -!!! error TS2341: Property 'C1.sf' is inaccessible. +!!! error TS2445: Property 'sf' is protected and only accessible within class 'C1' and its subclasses. // All of these should be errors c2.x; ~~~~ -!!! error TS2341: Property 'C1.x' is inaccessible. +!!! error TS2445: Property 'x' is protected and only accessible within class 'C1' and its subclasses. c2.f(); ~~~~ -!!! error TS2341: Property 'C2.f' is inaccessible. +!!! error TS2445: Property 'f' is protected and only accessible within class 'C2' and its subclasses. C2.sx; ~~~~~ -!!! error TS2341: Property 'C1.sx' is inaccessible. +!!! error TS2445: Property 'sx' is protected and only accessible within class 'C1' and its subclasses. C2.sf(); ~~~~~ -!!! error TS2341: Property 'C2.sf' is inaccessible. +!!! error TS2445: Property 'sf' is protected and only accessible within class 'C2' and its subclasses. // All of these should be ok c3.x; @@ -103,10 +103,10 @@ tests/cases/compiler/protectedMembers.ts(112,7): error TS2416: Class 'B3' incorr static foo(a: A, b: B, c: C, d: D, e: E) { a.x = 1; // Error, access must be through C or type derived from C ~~~ -!!! error TS2341: Property 'A.x' is inaccessible. +!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'C'. b.x = 1; // Error, access must be through C or type derived from C ~~~ -!!! error TS2341: Property 'A.x' is inaccessible. +!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'C'. c.x = 1; d.x = 1; e.x = 1; @@ -140,7 +140,7 @@ tests/cases/compiler/protectedMembers.ts(112,7): error TS2416: Class 'B3' incorr a1 = b1; // Error, B1 doesn't derive from A1 ~~ !!! error TS2322: Type 'B1' is not assignable to type 'A1': -!!! error TS2322: Property 'x' is protected but type 'B1' is not derived from type 'A1'. +!!! error TS2322: Property 'x' is protected but type 'B1' is not a class derived from 'A1'. b1 = a1; // Error, x is protected in A1 but public in B1 ~~ !!! error TS2322: Type 'A1' is not assignable to type 'B1': diff --git a/tests/baselines/reference/superPropertyAccess.errors.txt b/tests/baselines/reference/superPropertyAccess.errors.txt index 9afee0dcb89a9..4880bf66f17c4 100644 --- a/tests/baselines/reference/superPropertyAccess.errors.txt +++ b/tests/baselines/reference/superPropertyAccess.errors.txt @@ -1,7 +1,7 @@ tests/cases/compiler/superPropertyAccess.ts(8,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/superPropertyAccess.ts(9,9): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. tests/cases/compiler/superPropertyAccess.ts(22,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword -tests/cases/compiler/superPropertyAccess.ts(24,9): error TS2341: Property 'MyBase.p1' is inaccessible. +tests/cases/compiler/superPropertyAccess.ts(24,9): error TS2341: Property 'p1' is private and only accessible within class 'MyBase'. tests/cases/compiler/superPropertyAccess.ts(26,24): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword tests/cases/compiler/superPropertyAccess.ts(28,24): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword tests/cases/compiler/superPropertyAccess.ts(32,15): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword @@ -40,7 +40,7 @@ tests/cases/compiler/superPropertyAccess.ts(34,23): error TS2340: Only public an super.p1(); // Should error, private not public instance member function ~~~~~~~~ -!!! error TS2341: Property 'MyBase.p1' is inaccessible. +!!! error TS2341: Property 'p1' is private and only accessible within class 'MyBase'. var l1 = super.d1; // Should error, instance data property not a public instance member function ~~ From b5b0777ad51fa6e7de362fad5e10db95a5ab91a3 Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 19 Sep 2014 14:01:07 -0700 Subject: [PATCH 5/5] More tests for protected members --- .../classConstructorAccessibility.errors.txt | 20 ++- .../classPropertyAsProtected.errors.txt | 62 ++++++++ .../constructorParameterProperties.errors.txt | 21 ++- .../constructorParameterProperties.js | 17 ++- ...constructorParameterProperties2.errors.txt | 16 +- .../constructorParameterProperties2.js | 19 ++- ...aceExtendingClassWithProtecteds.errors.txt | 74 ++++++++++ ...AnInterfaceExtendingClassWithProtecteds.js | 103 +++++++++++++ ...aceExtendingClassWithProtecteds.errors.txt | 26 ++++ .../interfaceExtendingClassWithProtecteds.js | 26 ++++ ...ceExtendingClassWithProtecteds2.errors.txt | 51 +++++++ .../interfaceExtendingClassWithProtecteds2.js | 49 ++++++ ...ectedClassPropertyAccessibleWithinClass.js | 117 +++++++++++++++ ...edClassPropertyAccessibleWithinClass.types | 139 ++++++++++++++++++ ...edClassPropertyAccessibleWithinSubclass.js | 73 +++++++++ ...lassPropertyAccessibleWithinSubclass.types | 78 ++++++++++ ...ctedInstanceMemberAccessibility.errors.txt | 86 +++++++++++ .../protectedInstanceMemberAccessibility.js | 100 +++++++++++++ .../classConstructorAccessibility.ts | 10 ++ .../constructorParameterProperties.ts | 8 +- .../constructorParameterProperties2.ts | 10 +- .../accessibility/classPropertyAsProtected.ts | 23 +++ ...ectedClassPropertyAccessibleWithinClass.ts | 31 ++++ ...edClassPropertyAccessibleWithinSubclass.ts | 19 +++ .../protectedInstanceMemberAccessibility.ts | 43 ++++++ ...AnInterfaceExtendingClassWithProtecteds.ts | 40 +++++ .../interfaceExtendingClassWithProtecteds.ts | 15 ++ .../interfaceExtendingClassWithProtecteds2.ts | 27 ++++ 28 files changed, 1283 insertions(+), 20 deletions(-) create mode 100644 tests/baselines/reference/classPropertyAsProtected.errors.txt create mode 100644 tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt create mode 100644 tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.js create mode 100644 tests/baselines/reference/interfaceExtendingClassWithProtecteds.errors.txt create mode 100644 tests/baselines/reference/interfaceExtendingClassWithProtecteds.js create mode 100644 tests/baselines/reference/interfaceExtendingClassWithProtecteds2.errors.txt create mode 100644 tests/baselines/reference/interfaceExtendingClassWithProtecteds2.js create mode 100644 tests/baselines/reference/protectedClassPropertyAccessibleWithinClass.js create mode 100644 tests/baselines/reference/protectedClassPropertyAccessibleWithinClass.types create mode 100644 tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass.js create mode 100644 tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass.types create mode 100644 tests/baselines/reference/protectedInstanceMemberAccessibility.errors.txt create mode 100644 tests/baselines/reference/protectedInstanceMemberAccessibility.js create mode 100644 tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts create mode 100644 tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinClass.ts create mode 100644 tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass.ts create mode 100644 tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts create mode 100644 tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts create mode 100644 tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds.ts create mode 100644 tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds2.ts diff --git a/tests/baselines/reference/classConstructorAccessibility.errors.txt b/tests/baselines/reference/classConstructorAccessibility.errors.txt index 783d8a3ea1c4a..c22f3593bc57f 100644 --- a/tests/baselines/reference/classConstructorAccessibility.errors.txt +++ b/tests/baselines/reference/classConstructorAccessibility.errors.txt @@ -1,8 +1,10 @@ tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(6,5): error TS1089: 'private' modifier cannot appear on a constructor declaration. -tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(18,9): error TS1089: 'private' modifier cannot appear on a constructor declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(10,5): error TS1089: 'protected' modifier cannot appear on a constructor declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(23,9): error TS1089: 'private' modifier cannot appear on a constructor declaration. +tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts(27,9): error TS1089: 'protected' modifier cannot appear on a constructor declaration. -==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts (2 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts (4 errors) ==== class C { public constructor(public x: number) { } } @@ -13,8 +15,15 @@ tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessib !!! error TS1089: 'private' modifier cannot appear on a constructor declaration. } + class E { + protected constructor(public x: number) { } // error + ~~~~~~~~~ +!!! error TS1089: 'protected' modifier cannot appear on a constructor declaration. + } + var c = new C(1); var d = new D(1); + var e = new E(1); module Generic { class C { @@ -27,7 +36,14 @@ tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessib !!! error TS1089: 'private' modifier cannot appear on a constructor declaration. } + class E { + protected constructor(public x: T) { } // error + ~~~~~~~~~ +!!! error TS1089: 'protected' modifier cannot appear on a constructor declaration. + } + var c = new C(1); var d = new D(1); + var e = new E(1); } \ No newline at end of file diff --git a/tests/baselines/reference/classPropertyAsProtected.errors.txt b/tests/baselines/reference/classPropertyAsProtected.errors.txt new file mode 100644 index 0000000000000..570ebc718ac42 --- /dev/null +++ b/tests/baselines/reference/classPropertyAsProtected.errors.txt @@ -0,0 +1,62 @@ +tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts(3,19): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts(4,19): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts(8,26): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts(9,26): error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. +tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts(15,1): error TS2445: Property 'x' is protected and only accessible within class 'C' and its subclasses. +tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts(16,1): error TS2445: Property 'y' is protected and only accessible within class 'C' and its subclasses. +tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts(17,1): error TS2445: Property 'y' is protected and only accessible within class 'C' and its subclasses. +tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts(18,1): error TS2445: Property 'foo' is protected and only accessible within class 'C' and its subclasses. +tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts(20,1): error TS2445: Property 'a' is protected and only accessible within class 'C' and its subclasses. +tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts(21,1): error TS2445: Property 'b' is protected and only accessible within class 'C' and its subclasses. +tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts(22,1): error TS2445: Property 'b' is protected and only accessible within class 'C' and its subclasses. +tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts(23,1): error TS2445: Property 'foo' is protected and only accessible within class 'C' and its subclasses. + + +==== tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts (12 errors) ==== + class C { + protected x: string; + protected get y() { return null; } + ~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + protected set y(x) { } + ~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + protected foo() { } + + protected static a: string; + protected static get b() { return null; } + ~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + protected static set b(x) { } + ~ +!!! error TS1056: Accessors are only available when targeting ECMAScript 5 and higher. + protected static foo() { } + } + + var c: C; + // all errors + c.x; + ~~~ +!!! error TS2445: Property 'x' is protected and only accessible within class 'C' and its subclasses. + c.y; + ~~~ +!!! error TS2445: Property 'y' is protected and only accessible within class 'C' and its subclasses. + c.y = 1; + ~~~ +!!! error TS2445: Property 'y' is protected and only accessible within class 'C' and its subclasses. + c.foo(); + ~~~~~ +!!! error TS2445: Property 'foo' is protected and only accessible within class 'C' and its subclasses. + + C.a; + ~~~ +!!! error TS2445: Property 'a' is protected and only accessible within class 'C' and its subclasses. + C.b(); + ~~~ +!!! error TS2445: Property 'b' is protected and only accessible within class 'C' and its subclasses. + C.b = 1; + ~~~ +!!! error TS2445: Property 'b' is protected and only accessible within class 'C' and its subclasses. + C.foo(); + ~~~~~ +!!! error TS2445: Property 'foo' is protected and only accessible within class 'C' and its subclasses. \ No newline at end of file diff --git a/tests/baselines/reference/constructorParameterProperties.errors.txt b/tests/baselines/reference/constructorParameterProperties.errors.txt index 63018d57024eb..ab9bebe9d2d0f 100644 --- a/tests/baselines/reference/constructorParameterProperties.errors.txt +++ b/tests/baselines/reference/constructorParameterProperties.errors.txt @@ -1,12 +1,14 @@ tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts(8,10): error TS2341: Property 'x' is private and only accessible within class 'C'. -tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts(17,10): error TS2341: Property 'x' is private and only accessible within class 'D'. -tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts(18,12): error TS2339: Property 'a' does not exist on type 'D'. +tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts(9,10): error TS2445: Property 'z' is protected and only accessible within class 'C' and its subclasses. +tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts(18,10): error TS2341: Property 'x' is private and only accessible within class 'D'. +tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts(19,12): error TS2339: Property 'a' does not exist on type 'D'. +tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts(20,10): error TS2445: Property 'z' is protected and only accessible within class 'D' and its subclasses. -==== tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts (3 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts (5 errors) ==== class C { y: string; - constructor(private x: string) { } + constructor(private x: string, protected z: string) { } } var c: C; @@ -14,10 +16,13 @@ tests/cases/conformance/classes/constructorDeclarations/constructorParameters/co var r2 = c.x; // error ~~~ !!! error TS2341: Property 'x' is private and only accessible within class 'C'. + var r3 = c.z; // error + ~~~ +!!! error TS2445: Property 'z' is protected and only accessible within class 'C' and its subclasses. class D { y: T; - constructor(a: T, private x: T) { } + constructor(a: T, private x: T, protected z: T) { } } var d: D; @@ -27,4 +32,8 @@ tests/cases/conformance/classes/constructorDeclarations/constructorParameters/co !!! error TS2341: Property 'x' is private and only accessible within class 'D'. var r3 = d.a; // error ~ -!!! error TS2339: Property 'a' does not exist on type 'D'. \ No newline at end of file +!!! error TS2339: Property 'a' does not exist on type 'D'. + var r4 = d.z; // error + ~~~ +!!! error TS2445: Property 'z' is protected and only accessible within class 'D' and its subclasses. + \ No newline at end of file diff --git a/tests/baselines/reference/constructorParameterProperties.js b/tests/baselines/reference/constructorParameterProperties.js index 37ba30d24b05a..11446a316d39d 100644 --- a/tests/baselines/reference/constructorParameterProperties.js +++ b/tests/baselines/reference/constructorParameterProperties.js @@ -1,36 +1,42 @@ //// [constructorParameterProperties.ts] class C { y: string; - constructor(private x: string) { } + constructor(private x: string, protected z: string) { } } var c: C; var r = c.y; var r2 = c.x; // error +var r3 = c.z; // error class D { y: T; - constructor(a: T, private x: T) { } + constructor(a: T, private x: T, protected z: T) { } } var d: D; var r = d.y; var r2 = d.x; // error -var r3 = d.a; // error +var r3 = d.a; // error +var r4 = d.z; // error + //// [constructorParameterProperties.js] var C = (function () { - function C(x) { + function C(x, z) { this.x = x; + this.z = z; } return C; })(); var c; var r = c.y; var r2 = c.x; // error +var r3 = c.z; // error var D = (function () { - function D(a, x) { + function D(a, x, z) { this.x = x; + this.z = z; } return D; })(); @@ -38,3 +44,4 @@ var d; var r = d.y; var r2 = d.x; // error var r3 = d.a; // error +var r4 = d.z; // error diff --git a/tests/baselines/reference/constructorParameterProperties2.errors.txt b/tests/baselines/reference/constructorParameterProperties2.errors.txt index e6535bbbd54ca..df759fbe70911 100644 --- a/tests/baselines/reference/constructorParameterProperties2.errors.txt +++ b/tests/baselines/reference/constructorParameterProperties2.errors.txt @@ -1,8 +1,9 @@ tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties2.ts(11,24): error TS2300: Duplicate identifier 'y'. tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties2.ts(19,25): error TS2300: Duplicate identifier 'y'. +tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties2.ts(27,27): error TS2300: Duplicate identifier 'y'. -==== tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties2.ts (2 errors) ==== +==== tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties2.ts (3 errors) ==== class C { y: number; constructor(y: number) { } // ok @@ -29,4 +30,15 @@ tests/cases/conformance/classes/constructorDeclarations/constructorParameters/co } var e: E; - var r3 = e.y; // error \ No newline at end of file + var r3 = e.y; // error + + class F { + y: number; + constructor(protected y: number) { } // error + ~ +!!! error TS2300: Duplicate identifier 'y'. + } + + var f: F; + var r4 = f.y; // error + \ No newline at end of file diff --git a/tests/baselines/reference/constructorParameterProperties2.js b/tests/baselines/reference/constructorParameterProperties2.js index 8ad0c8b6ea632..02e4cf82c8403 100644 --- a/tests/baselines/reference/constructorParameterProperties2.js +++ b/tests/baselines/reference/constructorParameterProperties2.js @@ -21,7 +21,16 @@ class E { } var e: E; -var r3 = e.y; // error +var r3 = e.y; // error + +class F { + y: number; + constructor(protected y: number) { } // error +} + +var f: F; +var r4 = f.y; // error + //// [constructorParameterProperties2.js] var C = (function () { @@ -47,3 +56,11 @@ var E = (function () { })(); var e; var r3 = e.y; // error +var F = (function () { + function F(y) { + this.y = y; + } // error + return F; +})(); +var f; +var r4 = f.y; // error diff --git a/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt new file mode 100644 index 0000000000000..fc7cbbed97a9b --- /dev/null +++ b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.errors.txt @@ -0,0 +1,74 @@ +tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts(9,7): error TS2421: Class 'Bar' incorrectly implements interface 'I': + Property 'y' is missing in type 'Bar'. +tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts(12,7): error TS2421: Class 'Bar2' incorrectly implements interface 'I': + Property 'x' is missing in type 'Bar2'. +tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts(16,7): error TS2421: Class 'Bar3' incorrectly implements interface 'I': + Property 'x' is protected but type 'Bar3' is not a class derived from 'Foo'. +tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts(21,7): error TS2421: Class 'Bar4' incorrectly implements interface 'I': + Property 'x' is protected but type 'Bar4' is not a class derived from 'Foo'. +tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts(26,7): error TS2421: Class 'Bar5' incorrectly implements interface 'I': + Property 'y' is missing in type 'Bar5'. +tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts(29,7): error TS2421: Class 'Bar6' incorrectly implements interface 'I': + Property 'y' is protected in type 'Bar6' but public in type 'I'. + + +==== tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts (6 errors) ==== + class Foo { + protected x: string; + } + + interface I extends Foo { + y: number; + } + + class Bar implements I { // error + ~~~ +!!! error TS2421: Class 'Bar' incorrectly implements interface 'I': +!!! error TS2421: Property 'y' is missing in type 'Bar'. + } + + class Bar2 implements I { // error + ~~~~ +!!! error TS2421: Class 'Bar2' incorrectly implements interface 'I': +!!! error TS2421: Property 'x' is missing in type 'Bar2'. + y: number; + } + + class Bar3 implements I { // error + ~~~~ +!!! error TS2421: Class 'Bar3' incorrectly implements interface 'I': +!!! error TS2421: Property 'x' is protected but type 'Bar3' is not a class derived from 'Foo'. + x: string; + y: number; + } + + class Bar4 implements I { // error + ~~~~ +!!! error TS2421: Class 'Bar4' incorrectly implements interface 'I': +!!! error TS2421: Property 'x' is protected but type 'Bar4' is not a class derived from 'Foo'. + protected x: string; + y: number; + } + + class Bar5 extends Foo implements I { // error + ~~~~ +!!! error TS2421: Class 'Bar5' incorrectly implements interface 'I': +!!! error TS2421: Property 'y' is missing in type 'Bar5'. + } + + class Bar6 extends Foo implements I { // error + ~~~~ +!!! error TS2421: Class 'Bar6' incorrectly implements interface 'I': +!!! error TS2421: Property 'y' is protected in type 'Bar6' but public in type 'I'. + protected y: number; + } + + class Bar7 extends Foo implements I { + y: number; + } + + class Bar8 extends Foo implements I { + x: string; + y: number; + } + \ No newline at end of file diff --git a/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.js b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.js new file mode 100644 index 0000000000000..1a79496bd12d1 --- /dev/null +++ b/tests/baselines/reference/implementingAnInterfaceExtendingClassWithProtecteds.js @@ -0,0 +1,103 @@ +//// [implementingAnInterfaceExtendingClassWithProtecteds.ts] +class Foo { + protected x: string; +} + +interface I extends Foo { + y: number; +} + +class Bar implements I { // error +} + +class Bar2 implements I { // error + y: number; +} + +class Bar3 implements I { // error + x: string; + y: number; +} + +class Bar4 implements I { // error + protected x: string; + y: number; +} + +class Bar5 extends Foo implements I { // error +} + +class Bar6 extends Foo implements I { // error + protected y: number; +} + +class Bar7 extends Foo implements I { + y: number; +} + +class Bar8 extends Foo implements I { + x: string; + y: number; +} + + +//// [implementingAnInterfaceExtendingClassWithProtecteds.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var Bar = (function () { + function Bar() { + } + return Bar; +})(); +var Bar2 = (function () { + function Bar2() { + } + return Bar2; +})(); +var Bar3 = (function () { + function Bar3() { + } + return Bar3; +})(); +var Bar4 = (function () { + function Bar4() { + } + return Bar4; +})(); +var Bar5 = (function (_super) { + __extends(Bar5, _super); + function Bar5() { + _super.apply(this, arguments); + } + return Bar5; +})(Foo); +var Bar6 = (function (_super) { + __extends(Bar6, _super); + function Bar6() { + _super.apply(this, arguments); + } + return Bar6; +})(Foo); +var Bar7 = (function (_super) { + __extends(Bar7, _super); + function Bar7() { + _super.apply(this, arguments); + } + return Bar7; +})(Foo); +var Bar8 = (function (_super) { + __extends(Bar8, _super); + function Bar8() { + _super.apply(this, arguments); + } + return Bar8; +})(Foo); diff --git a/tests/baselines/reference/interfaceExtendingClassWithProtecteds.errors.txt b/tests/baselines/reference/interfaceExtendingClassWithProtecteds.errors.txt new file mode 100644 index 0000000000000..1cbc921e1ac48 --- /dev/null +++ b/tests/baselines/reference/interfaceExtendingClassWithProtecteds.errors.txt @@ -0,0 +1,26 @@ +tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds.ts(5,11): error TS2429: Interface 'I' incorrectly extends interface 'Foo': + Property 'x' is protected but type 'I' is not a class derived from 'Foo'. +tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds.ts(15,10): error TS2445: Property 'x' is protected and only accessible within class 'Foo' and its subclasses. + + +==== tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds.ts (2 errors) ==== + class Foo { + protected x: string; + } + + interface I extends Foo { // error + ~ +!!! error TS2429: Interface 'I' incorrectly extends interface 'Foo': +!!! error TS2429: Property 'x' is protected but type 'I' is not a class derived from 'Foo'. + x: string; + } + + interface I2 extends Foo { + y: string; + } + + var i: I2; + var r = i.y; + var r2 = i.x; // error + ~~~ +!!! error TS2445: Property 'x' is protected and only accessible within class 'Foo' and its subclasses. \ No newline at end of file diff --git a/tests/baselines/reference/interfaceExtendingClassWithProtecteds.js b/tests/baselines/reference/interfaceExtendingClassWithProtecteds.js new file mode 100644 index 0000000000000..f2d95812fd2a6 --- /dev/null +++ b/tests/baselines/reference/interfaceExtendingClassWithProtecteds.js @@ -0,0 +1,26 @@ +//// [interfaceExtendingClassWithProtecteds.ts] +class Foo { + protected x: string; +} + +interface I extends Foo { // error + x: string; +} + +interface I2 extends Foo { + y: string; +} + +var i: I2; +var r = i.y; +var r2 = i.x; // error + +//// [interfaceExtendingClassWithProtecteds.js] +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var i; +var r = i.y; +var r2 = i.x; // error diff --git a/tests/baselines/reference/interfaceExtendingClassWithProtecteds2.errors.txt b/tests/baselines/reference/interfaceExtendingClassWithProtecteds2.errors.txt new file mode 100644 index 0000000000000..4e5b636401053 --- /dev/null +++ b/tests/baselines/reference/interfaceExtendingClassWithProtecteds2.errors.txt @@ -0,0 +1,51 @@ +tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds2.ts(9,11): error TS2320: Interface 'I3' cannot simultaneously extend types 'Foo' and 'Bar': + Named properties 'x' of types 'Foo' and 'Bar' are not identical. +tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds2.ts(12,11): error TS2429: Interface 'I4' incorrectly extends interface 'Bar': + Property 'x' is protected but type 'I4' is not a class derived from 'Bar'. +tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds2.ts(12,11): error TS2429: Interface 'I4' incorrectly extends interface 'Foo': + Property 'x' is protected but type 'I4' is not a class derived from 'Foo'. +tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds2.ts(26,10): error TS2445: Property 'x' is protected and only accessible within class 'Foo' and its subclasses. +tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds2.ts(27,10): error TS2445: Property 'y' is protected and only accessible within class 'Baz' and its subclasses. + + +==== tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds2.ts (5 errors) ==== + class Foo { + protected x: string; + } + + class Bar { + protected x: string; + } + + interface I3 extends Foo, Bar { // error + ~~ +!!! error TS2320: Interface 'I3' cannot simultaneously extend types 'Foo' and 'Bar': +!!! error TS2320: Named properties 'x' of types 'Foo' and 'Bar' are not identical. + } + + interface I4 extends Foo, Bar { // error + ~~ +!!! error TS2429: Interface 'I4' incorrectly extends interface 'Bar': +!!! error TS2429: Property 'x' is protected but type 'I4' is not a class derived from 'Bar'. + ~~ +!!! error TS2429: Interface 'I4' incorrectly extends interface 'Foo': +!!! error TS2429: Property 'x' is protected but type 'I4' is not a class derived from 'Foo'. + x: string; + } + + class Baz { + protected y: string; + } + + interface I5 extends Foo, Baz { + z: string; + } + + var i: I5; + var r: string = i.z; + var r2 = i.x; // error + ~~~ +!!! error TS2445: Property 'x' is protected and only accessible within class 'Foo' and its subclasses. + var r3 = i.y; // error + ~~~ +!!! error TS2445: Property 'y' is protected and only accessible within class 'Baz' and its subclasses. \ No newline at end of file diff --git a/tests/baselines/reference/interfaceExtendingClassWithProtecteds2.js b/tests/baselines/reference/interfaceExtendingClassWithProtecteds2.js new file mode 100644 index 0000000000000..277c32a10c154 --- /dev/null +++ b/tests/baselines/reference/interfaceExtendingClassWithProtecteds2.js @@ -0,0 +1,49 @@ +//// [interfaceExtendingClassWithProtecteds2.ts] +class Foo { + protected x: string; +} + +class Bar { + protected x: string; +} + +interface I3 extends Foo, Bar { // error +} + +interface I4 extends Foo, Bar { // error + x: string; +} + +class Baz { + protected y: string; +} + +interface I5 extends Foo, Baz { + z: string; +} + +var i: I5; +var r: string = i.z; +var r2 = i.x; // error +var r3 = i.y; // error + +//// [interfaceExtendingClassWithProtecteds2.js] +var Foo = (function () { + function Foo() { + } + return Foo; +})(); +var Bar = (function () { + function Bar() { + } + return Bar; +})(); +var Baz = (function () { + function Baz() { + } + return Baz; +})(); +var i; +var r = i.z; +var r2 = i.x; // error +var r3 = i.y; // error diff --git a/tests/baselines/reference/protectedClassPropertyAccessibleWithinClass.js b/tests/baselines/reference/protectedClassPropertyAccessibleWithinClass.js new file mode 100644 index 0000000000000..992011ee4af75 --- /dev/null +++ b/tests/baselines/reference/protectedClassPropertyAccessibleWithinClass.js @@ -0,0 +1,117 @@ +//// [protectedClassPropertyAccessibleWithinClass.ts] +// no errors + +class C { + protected x: string; + protected get y() { return this.x; } + protected set y(x) { this.y = this.x; } + protected foo() { return this.foo; } + + protected static x: string; + protected static get y() { return this.x; } + protected static set y(x) { this.y = this.x; } + protected static foo() { return this.foo; } + protected static bar() { this.foo(); } +} + +// added level of function nesting +class C2 { + protected x: string; + protected get y() { () => this.x; return null; } + protected set y(x) { () => { this.y = this.x; } } + protected foo() { () => this.foo; } + + protected static x: string; + protected static get y() { () => this.x; return null; } + protected static set y(x) { + () => { this.y = this.x; } + } + protected static foo() { () => this.foo; } + protected static bar() { () => this.foo(); } +} + + +//// [protectedClassPropertyAccessibleWithinClass.js] +// no errors +var C = (function () { + function C() { + } + Object.defineProperty(C.prototype, "y", { + get: function () { + return this.x; + }, + set: function (x) { + this.y = this.x; + }, + enumerable: true, + configurable: true + }); + C.prototype.foo = function () { + return this.foo; + }; + Object.defineProperty(C, "y", { + get: function () { + return this.x; + }, + set: function (x) { + this.y = this.x; + }, + enumerable: true, + configurable: true + }); + C.foo = function () { + return this.foo; + }; + C.bar = function () { + this.foo(); + }; + return C; +})(); +// added level of function nesting +var C2 = (function () { + function C2() { + } + Object.defineProperty(C2.prototype, "y", { + get: function () { + var _this = this; + (function () { return _this.x; }); + return null; + }, + set: function (x) { + var _this = this; + (function () { + _this.y = _this.x; + }); + }, + enumerable: true, + configurable: true + }); + C2.prototype.foo = function () { + var _this = this; + (function () { return _this.foo; }); + }; + Object.defineProperty(C2, "y", { + get: function () { + var _this = this; + (function () { return _this.x; }); + return null; + }, + set: function (x) { + var _this = this; + (function () { + _this.y = _this.x; + }); + }, + enumerable: true, + configurable: true + }); + C2.foo = function () { + var _this = this; + (function () { return _this.foo; }); + }; + C2.bar = function () { + var _this = this; + (function () { return _this.foo(); }); + }; + return C2; +})(); diff --git a/tests/baselines/reference/protectedClassPropertyAccessibleWithinClass.types b/tests/baselines/reference/protectedClassPropertyAccessibleWithinClass.types new file mode 100644 index 0000000000000..241b3cfc7a161 --- /dev/null +++ b/tests/baselines/reference/protectedClassPropertyAccessibleWithinClass.types @@ -0,0 +1,139 @@ +=== tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinClass.ts === +// no errors + +class C { +>C : C + + protected x: string; +>x : string + + protected get y() { return this.x; } +>y : string +>this.x : string +>this : C +>x : string + + protected set y(x) { this.y = this.x; } +>y : string +>x : string +>this.y = this.x : string +>this.y : string +>this : C +>y : string +>this.x : string +>this : C +>x : string + + protected foo() { return this.foo; } +>foo : () => any +>this.foo : () => any +>this : C +>foo : () => any + + protected static x: string; +>x : string + + protected static get y() { return this.x; } +>y : string +>this.x : string +>this : typeof C +>x : string + + protected static set y(x) { this.y = this.x; } +>y : string +>x : string +>this.y = this.x : string +>this.y : string +>this : typeof C +>y : string +>this.x : string +>this : typeof C +>x : string + + protected static foo() { return this.foo; } +>foo : () => typeof C.foo +>this.foo : () => typeof C.foo +>this : typeof C +>foo : () => typeof C.foo + + protected static bar() { this.foo(); } +>bar : () => void +>this.foo() : () => typeof C.foo +>this.foo : () => typeof C.foo +>this : typeof C +>foo : () => typeof C.foo +} + +// added level of function nesting +class C2 { +>C2 : C2 + + protected x: string; +>x : string + + protected get y() { () => this.x; return null; } +>y : any +>() => this.x : () => string +>this.x : string +>this : C2 +>x : string + + protected set y(x) { () => { this.y = this.x; } } +>y : any +>x : any +>() => { this.y = this.x; } : () => void +>this.y = this.x : string +>this.y : any +>this : C2 +>y : any +>this.x : string +>this : C2 +>x : string + + protected foo() { () => this.foo; } +>foo : () => void +>() => this.foo : () => () => void +>this.foo : () => void +>this : C2 +>foo : () => void + + protected static x: string; +>x : string + + protected static get y() { () => this.x; return null; } +>y : any +>() => this.x : () => string +>this.x : string +>this : typeof C2 +>x : string + + protected static set y(x) { +>y : any +>x : any + + () => { this.y = this.x; } +>() => { this.y = this.x; } : () => void +>this.y = this.x : string +>this.y : any +>this : typeof C2 +>y : any +>this.x : string +>this : typeof C2 +>x : string + } + protected static foo() { () => this.foo; } +>foo : () => void +>() => this.foo : () => () => void +>this.foo : () => void +>this : typeof C2 +>foo : () => void + + protected static bar() { () => this.foo(); } +>bar : () => void +>() => this.foo() : () => void +>this.foo() : void +>this.foo : () => void +>this : typeof C2 +>foo : () => void +} + diff --git a/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass.js b/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass.js new file mode 100644 index 0000000000000..381d10f43ea9c --- /dev/null +++ b/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass.js @@ -0,0 +1,73 @@ +//// [protectedClassPropertyAccessibleWithinSubclass.ts] +// no errors + +class B { + protected x: string; + protected static x: string; +} + +class C extends B { + protected get y() { return this.x; } + protected set y(x) { this.y = this.x; } + protected foo() { return this.x; } + protected bar() { return this.foo(); } + + protected static get y() { return this.x; } + protected static set y(x) { this.y = this.x; } + protected static foo() { return this.x; } + protected static bar() { this.foo(); } +} + + +//// [protectedClassPropertyAccessibleWithinSubclass.js] +// no errors +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var B = (function () { + function B() { + } + return B; +})(); +var C = (function (_super) { + __extends(C, _super); + function C() { + _super.apply(this, arguments); + } + Object.defineProperty(C.prototype, "y", { + get: function () { + return this.x; + }, + set: function (x) { + this.y = this.x; + }, + enumerable: true, + configurable: true + }); + C.prototype.foo = function () { + return this.x; + }; + C.prototype.bar = function () { + return this.foo(); + }; + Object.defineProperty(C, "y", { + get: function () { + return this.x; + }, + set: function (x) { + this.y = this.x; + }, + enumerable: true, + configurable: true + }); + C.foo = function () { + return this.x; + }; + C.bar = function () { + this.foo(); + }; + return C; +})(B); diff --git a/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass.types b/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass.types new file mode 100644 index 0000000000000..bd230239d47b9 --- /dev/null +++ b/tests/baselines/reference/protectedClassPropertyAccessibleWithinSubclass.types @@ -0,0 +1,78 @@ +=== tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass.ts === +// no errors + +class B { +>B : B + + protected x: string; +>x : string + + protected static x: string; +>x : string +} + +class C extends B { +>C : C +>B : B + + protected get y() { return this.x; } +>y : string +>this.x : string +>this : C +>x : string + + protected set y(x) { this.y = this.x; } +>y : string +>x : string +>this.y = this.x : string +>this.y : string +>this : C +>y : string +>this.x : string +>this : C +>x : string + + protected foo() { return this.x; } +>foo : () => string +>this.x : string +>this : C +>x : string + + protected bar() { return this.foo(); } +>bar : () => string +>this.foo() : string +>this.foo : () => string +>this : C +>foo : () => string + + protected static get y() { return this.x; } +>y : string +>this.x : string +>this : typeof C +>x : string + + protected static set y(x) { this.y = this.x; } +>y : string +>x : string +>this.y = this.x : string +>this.y : string +>this : typeof C +>y : string +>this.x : string +>this : typeof C +>x : string + + protected static foo() { return this.x; } +>foo : () => string +>this.x : string +>this : typeof C +>x : string + + protected static bar() { this.foo(); } +>bar : () => void +>this.foo() : string +>this.foo : () => string +>this : typeof C +>foo : () => string +} + diff --git a/tests/baselines/reference/protectedInstanceMemberAccessibility.errors.txt b/tests/baselines/reference/protectedInstanceMemberAccessibility.errors.txt new file mode 100644 index 0000000000000..03671925febc1 --- /dev/null +++ b/tests/baselines/reference/protectedInstanceMemberAccessibility.errors.txt @@ -0,0 +1,86 @@ +tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts(14,23): error TS2339: Property 'z' does not exist on type 'B'. +tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts(16,24): error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword +tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts(18,24): error TS2339: Property 'y' does not exist on type 'A'. +tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts(19,24): error TS2339: Property 'z' does not exist on type 'A'. +tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts(22,18): error TS2446: Property 'x' is protected and only accessible through an instance of class 'B'. +tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts(23,18): error TS2446: Property 'f' is protected and only accessible through an instance of class 'B'. +tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts(24,20): error TS2339: Property 'y' does not exist on type 'A'. +tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts(25,20): error TS2339: Property 'z' does not exist on type 'A'. +tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts(31,20): error TS2339: Property 'z' does not exist on type 'B'. +tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts(34,18): error TS2446: Property 'x' is protected and only accessible through an instance of class 'B'. +tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts(35,18): error TS2446: Property 'f' is protected and only accessible through an instance of class 'B'. +tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts(36,20): error TS2339: Property 'y' does not exist on type 'C'. +tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts(37,18): error TS2445: Property 'z' is protected and only accessible within class 'C' and its subclasses. + + +==== tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts (13 errors) ==== + class A { + protected x: string; + protected f(): string { + return "hello"; + } + } + + class B extends A { + protected y: string; + g() { + var t1 = this.x; + var t2 = this.f(); + var t3 = this.y; + var t4 = this.z; // error + ~ +!!! error TS2339: Property 'z' does not exist on type 'B'. + + var s1 = super.x; // error + ~ +!!! error TS2340: Only public and protected methods of the base class are accessible via the 'super' keyword + var s2 = super.f(); + var s3 = super.y; // error + ~ +!!! error TS2339: Property 'y' does not exist on type 'A'. + var s4 = super.z; // error + ~ +!!! error TS2339: Property 'z' does not exist on type 'A'. + + var a: A; + var a1 = a.x; // error + ~~~ +!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'B'. + var a2 = a.f(); // error + ~~~ +!!! error TS2446: Property 'f' is protected and only accessible through an instance of class 'B'. + var a3 = a.y; // error + ~ +!!! error TS2339: Property 'y' does not exist on type 'A'. + var a4 = a.z; // error + ~ +!!! error TS2339: Property 'z' does not exist on type 'A'. + + var b: B; + var b1 = b.x; + var b2 = b.f(); + var b3 = b.y; + var b4 = b.z; // error + ~ +!!! error TS2339: Property 'z' does not exist on type 'B'. + + var c: C; + var c1 = c.x; // error + ~~~ +!!! error TS2446: Property 'x' is protected and only accessible through an instance of class 'B'. + var c2 = c.f(); // error + ~~~ +!!! error TS2446: Property 'f' is protected and only accessible through an instance of class 'B'. + var c3 = c.y; // error + ~ +!!! error TS2339: Property 'y' does not exist on type 'C'. + var c4 = c.z; // error + ~~~ +!!! error TS2445: Property 'z' is protected and only accessible within class 'C' and its subclasses. + } + } + + class C extends A { + protected z: string; + } + \ No newline at end of file diff --git a/tests/baselines/reference/protectedInstanceMemberAccessibility.js b/tests/baselines/reference/protectedInstanceMemberAccessibility.js new file mode 100644 index 0000000000000..de7a6e0d00e7f --- /dev/null +++ b/tests/baselines/reference/protectedInstanceMemberAccessibility.js @@ -0,0 +1,100 @@ +//// [protectedInstanceMemberAccessibility.ts] +class A { + protected x: string; + protected f(): string { + return "hello"; + } +} + +class B extends A { + protected y: string; + g() { + var t1 = this.x; + var t2 = this.f(); + var t3 = this.y; + var t4 = this.z; // error + + var s1 = super.x; // error + var s2 = super.f(); + var s3 = super.y; // error + var s4 = super.z; // error + + var a: A; + var a1 = a.x; // error + var a2 = a.f(); // error + var a3 = a.y; // error + var a4 = a.z; // error + + var b: B; + var b1 = b.x; + var b2 = b.f(); + var b3 = b.y; + var b4 = b.z; // error + + var c: C; + var c1 = c.x; // error + var c2 = c.f(); // error + var c3 = c.y; // error + var c4 = c.z; // error + } +} + +class C extends A { + protected z: string; +} + + +//// [protectedInstanceMemberAccessibility.js] +var __extends = this.__extends || function (d, b) { + for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; + function __() { this.constructor = d; } + __.prototype = b.prototype; + d.prototype = new __(); +}; +var A = (function () { + function A() { + } + A.prototype.f = function () { + return "hello"; + }; + return A; +})(); +var B = (function (_super) { + __extends(B, _super); + function B() { + _super.apply(this, arguments); + } + B.prototype.g = function () { + var t1 = this.x; + var t2 = this.f(); + var t3 = this.y; + var t4 = this.z; // error + var s1 = _super.prototype.x; // error + var s2 = _super.prototype.f.call(this); + var s3 = _super.prototype.y; // error + var s4 = _super.prototype.z; // error + var a; + var a1 = a.x; // error + var a2 = a.f(); // error + var a3 = a.y; // error + var a4 = a.z; // error + var b; + var b1 = b.x; + var b2 = b.f(); + var b3 = b.y; + var b4 = b.z; // error + var c; + var c1 = c.x; // error + var c2 = c.f(); // error + var c3 = c.y; // error + var c4 = c.z; // error + }; + return B; +})(A); +var C = (function (_super) { + __extends(C, _super); + function C() { + _super.apply(this, arguments); + } + return C; +})(A); diff --git a/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts index 353ab012234d2..c2e4855e63a3b 100644 --- a/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts +++ b/tests/cases/conformance/classes/constructorDeclarations/classConstructorAccessibility.ts @@ -6,8 +6,13 @@ class D { private constructor(public x: number) { } // error } +class E { + protected constructor(public x: number) { } // error +} + var c = new C(1); var d = new D(1); +var e = new E(1); module Generic { class C { @@ -18,6 +23,11 @@ module Generic { private constructor(public x: T) { } // error } + class E { + protected constructor(public x: T) { } // error + } + var c = new C(1); var d = new D(1); + var e = new E(1); } diff --git a/tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts b/tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts index e3ea627f0c370..f4d63da1192fc 100644 --- a/tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts +++ b/tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties.ts @@ -1,18 +1,20 @@ class C { y: string; - constructor(private x: string) { } + constructor(private x: string, protected z: string) { } } var c: C; var r = c.y; var r2 = c.x; // error +var r3 = c.z; // error class D { y: T; - constructor(a: T, private x: T) { } + constructor(a: T, private x: T, protected z: T) { } } var d: D; var r = d.y; var r2 = d.x; // error -var r3 = d.a; // error \ No newline at end of file +var r3 = d.a; // error +var r4 = d.z; // error diff --git a/tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties2.ts b/tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties2.ts index 4d14e4bafbdce..b95891c0845e7 100644 --- a/tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties2.ts +++ b/tests/cases/conformance/classes/constructorDeclarations/constructorParameters/constructorParameterProperties2.ts @@ -20,4 +20,12 @@ class E { } var e: E; -var r3 = e.y; // error \ No newline at end of file +var r3 = e.y; // error + +class F { + y: number; + constructor(protected y: number) { } // error +} + +var f: F; +var r4 = f.y; // error diff --git a/tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts b/tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts new file mode 100644 index 0000000000000..7efe159c058f2 --- /dev/null +++ b/tests/cases/conformance/classes/members/accessibility/classPropertyAsProtected.ts @@ -0,0 +1,23 @@ +class C { + protected x: string; + protected get y() { return null; } + protected set y(x) { } + protected foo() { } + + protected static a: string; + protected static get b() { return null; } + protected static set b(x) { } + protected static foo() { } +} + +var c: C; +// all errors +c.x; +c.y; +c.y = 1; +c.foo(); + +C.a; +C.b(); +C.b = 1; +C.foo(); \ No newline at end of file diff --git a/tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinClass.ts b/tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinClass.ts new file mode 100644 index 0000000000000..08f99af59727f --- /dev/null +++ b/tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinClass.ts @@ -0,0 +1,31 @@ +// @target: ES5 +// no errors + +class C { + protected x: string; + protected get y() { return this.x; } + protected set y(x) { this.y = this.x; } + protected foo() { return this.foo; } + + protected static x: string; + protected static get y() { return this.x; } + protected static set y(x) { this.y = this.x; } + protected static foo() { return this.foo; } + protected static bar() { this.foo(); } +} + +// added level of function nesting +class C2 { + protected x: string; + protected get y() { () => this.x; return null; } + protected set y(x) { () => { this.y = this.x; } } + protected foo() { () => this.foo; } + + protected static x: string; + protected static get y() { () => this.x; return null; } + protected static set y(x) { + () => { this.y = this.x; } + } + protected static foo() { () => this.foo; } + protected static bar() { () => this.foo(); } +} diff --git a/tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass.ts b/tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass.ts new file mode 100644 index 0000000000000..56c591f41ce6d --- /dev/null +++ b/tests/cases/conformance/classes/members/accessibility/protectedClassPropertyAccessibleWithinSubclass.ts @@ -0,0 +1,19 @@ +// @target: ES5 +// no errors + +class B { + protected x: string; + protected static x: string; +} + +class C extends B { + protected get y() { return this.x; } + protected set y(x) { this.y = this.x; } + protected foo() { return this.x; } + protected bar() { return this.foo(); } + + protected static get y() { return this.x; } + protected static set y(x) { this.y = this.x; } + protected static foo() { return this.x; } + protected static bar() { this.foo(); } +} diff --git a/tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts b/tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts new file mode 100644 index 0000000000000..b92d29d4d632d --- /dev/null +++ b/tests/cases/conformance/classes/members/accessibility/protectedInstanceMemberAccessibility.ts @@ -0,0 +1,43 @@ +class A { + protected x: string; + protected f(): string { + return "hello"; + } +} + +class B extends A { + protected y: string; + g() { + var t1 = this.x; + var t2 = this.f(); + var t3 = this.y; + var t4 = this.z; // error + + var s1 = super.x; // error + var s2 = super.f(); + var s3 = super.y; // error + var s4 = super.z; // error + + var a: A; + var a1 = a.x; // error + var a2 = a.f(); // error + var a3 = a.y; // error + var a4 = a.z; // error + + var b: B; + var b1 = b.x; + var b2 = b.f(); + var b3 = b.y; + var b4 = b.z; // error + + var c: C; + var c1 = c.x; // error + var c2 = c.f(); // error + var c3 = c.y; // error + var c4 = c.z; // error + } +} + +class C extends A { + protected z: string; +} diff --git a/tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts b/tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts new file mode 100644 index 0000000000000..746ab5bc393c4 --- /dev/null +++ b/tests/cases/conformance/interfaces/interfacesExtendingClasses/implementingAnInterfaceExtendingClassWithProtecteds.ts @@ -0,0 +1,40 @@ +class Foo { + protected x: string; +} + +interface I extends Foo { + y: number; +} + +class Bar implements I { // error +} + +class Bar2 implements I { // error + y: number; +} + +class Bar3 implements I { // error + x: string; + y: number; +} + +class Bar4 implements I { // error + protected x: string; + y: number; +} + +class Bar5 extends Foo implements I { // error +} + +class Bar6 extends Foo implements I { // error + protected y: number; +} + +class Bar7 extends Foo implements I { + y: number; +} + +class Bar8 extends Foo implements I { + x: string; + y: number; +} diff --git a/tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds.ts b/tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds.ts new file mode 100644 index 0000000000000..6a504a916da41 --- /dev/null +++ b/tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds.ts @@ -0,0 +1,15 @@ +class Foo { + protected x: string; +} + +interface I extends Foo { // error + x: string; +} + +interface I2 extends Foo { + y: string; +} + +var i: I2; +var r = i.y; +var r2 = i.x; // error \ No newline at end of file diff --git a/tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds2.ts b/tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds2.ts new file mode 100644 index 0000000000000..4663709bce8f2 --- /dev/null +++ b/tests/cases/conformance/interfaces/interfacesExtendingClasses/interfaceExtendingClassWithProtecteds2.ts @@ -0,0 +1,27 @@ +class Foo { + protected x: string; +} + +class Bar { + protected x: string; +} + +interface I3 extends Foo, Bar { // error +} + +interface I4 extends Foo, Bar { // error + x: string; +} + +class Baz { + protected y: string; +} + +interface I5 extends Foo, Baz { + z: string; +} + +var i: I5; +var r: string = i.z; +var r2 = i.x; // error +var r3 = i.y; // error \ No newline at end of file