Report error on Class/Interface heritage clause if it cant be accessed

Fixes #78 and #83
This commit is contained in:
Sheetal Nandi
2014-07-18 18:07:38 -07:00
parent 999b7fed92
commit 09ec1bb9ae
13 changed files with 1371 additions and 4 deletions

View File

@@ -99,6 +99,12 @@ module ts {
A_constructor_implementation_cannot_be_declared_in_an_ambient_context: { code: 1111, category: DiagnosticCategory.Error, key: "A constructor implementation cannot be declared in an ambient context." },
A_class_member_cannot_be_declared_optional: { code: 1112, category: DiagnosticCategory.Error, key: "A class member cannot be declared optional." },
Duplicate_identifier_0: { code: 2000, category: DiagnosticCategory.Error, key: "Duplicate identifier '{0}'." },
Extends_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 2018, category: DiagnosticCategory.Error, key: "Extends clause of exported class '{0}' has or is using private name '{1}'." },
Implements_clause_of_exported_class_0_has_or_is_using_private_name_1: { code: 2019, category: DiagnosticCategory.Error, key: "Implements clause of exported class '{0}' has or is using private name '{1}'." },
Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1: { code: 2020, category: DiagnosticCategory.Error, key: "Extends clause of exported interface '{0}' has or is using private name '{1}'." },
Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 2021, category: DiagnosticCategory.Error, key: "Extends clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." },
Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2: { code: 2022, category: DiagnosticCategory.Error, key: "Implements clause of exported class '{0}' has or is using name '{1}' from private module '{2}'." },
Extends_clause_of_exported_interface_0_has_or_is_using_name_1_from_private_module_2: { code: 2023, category: DiagnosticCategory.Error, key: "Extends clause of exported interface '{0}' has or is using name '{1}' from private module '{2}'." },
new_T_cannot_be_used_to_create_an_array_Use_new_Array_T_instead: { code: 2068, category: DiagnosticCategory.Error, key: "'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead." },
Multiple_constructor_implementations_are_not_allowed: { code: 2070, category: DiagnosticCategory.Error, key: "Multiple constructor implementations are not allowed." },
A_class_may_only_implement_another_class_or_interface: { code: 2074, category: DiagnosticCategory.Error, key: "A class may only implement another class or interface." },

View File

@@ -390,6 +390,30 @@
"category": "Error",
"code": 2000
},
"Extends clause of exported class '{0}' has or is using private name '{1}'.": {
"category": "Error",
"code": 2018
},
"Implements clause of exported class '{0}' has or is using private name '{1}'.": {
"category": "Error",
"code": 2019
},
"Extends clause of exported interface '{0}' has or is using private name '{1}'.": {
"category": "Error",
"code": 2020
},
"Extends clause of exported class '{0}' has or is using name '{1}' from private module '{2}'.": {
"category": "Error",
"code": 2021
},
"Implements clause of exported class '{0}' has or is using name '{1}' from private module '{2}'.": {
"category": "Error",
"code": 2022
},
"Extends clause of exported interface '{0}' has or is using name '{1}' from private module '{2}'.": {
"category": "Error",
"code": 2023
},
"'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.": {
"category": "Error",
"code": 2068

View File

@@ -2027,6 +2027,54 @@ module ts {
function emitHeritageClause(typeReferences: TypeReferenceNode[], isImplementsList: boolean) {
function emitTypeOfTypeReference(node: Node) {
function getHeritageClauseVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
var diagnosticMessage: DiagnosticMessage;
if (node.parent.kind === SyntaxKind.ClassDeclaration) {
// Class
if (symbolAccesibilityResult.accessibility == SymbolAccessibility.NotAccessible) {
if (symbolAccesibilityResult.errorModuleName) {
// Module is inaccessible
diagnosticMessage = isImplementsList ?
Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_name_1_from_private_module_2;
}
else {
// Class or Interface implemented/extended is inaccessible
diagnosticMessage = isImplementsList ?
Diagnostics.Implements_clause_of_exported_class_0_has_or_is_using_private_name_1 :
Diagnostics.Extends_clause_of_exported_class_0_has_or_is_using_private_name_1;
}
}
else {
// CannotBeNamed
// TODO(shkamat): CannotBeNamed error needs to be handled
}
}
else {
// Interface
if (symbolAccesibilityResult.accessibility == SymbolAccessibility.NotAccessible) {
if (symbolAccesibilityResult.errorModuleName) {
// Module is inaccessible
diagnosticMessage = Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_name_1_from_private_module_2;
}
else {
// interface is inaccessible
diagnosticMessage = Diagnostics.Extends_clause_of_exported_interface_0_has_or_is_using_private_name_1;
}
}
else {
// CannotBeNamed
// TODO(shkamat): CannotBeNamed error needs to be handled
}
}
return {
diagnosticMessage: diagnosticMessage,
errorNode: node,
typeName: (<Declaration>node.parent).name
}
}
getSymbolVisibilityDiagnosticMessage = getHeritageClauseVisibilityError;
resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.WriteArrayAsGenericType, writer);
}