Report errors if the type parameter uses constraint that is using private type/module

Fixes #86
This commit is contained in:
Sheetal Nandi
2014-07-18 18:11:04 -07:00
parent 09ec1bb9ae
commit 9fd95fcb95
18 changed files with 3259 additions and 245 deletions

View File

@@ -105,6 +105,22 @@ module ts {
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}'." },
TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 2208, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of constructor signature from exported interface has or is using private name '{1}'." },
TypeParameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1: { code: 2209, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of call signature from exported interface has or is using private name '{1}'." },
TypeParameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1: { code: 2210, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of public static method from exported class has or is using private name '{1}'." },
TypeParameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1: { code: 2211, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of public method from exported class has or is using private name '{1}'." },
TypeParameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1: { code: 2212, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of method from exported interface has or is using private name '{1}'." },
TypeParameter_0_of_exported_function_has_or_is_using_private_name_1: { code: 2213, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported function has or is using private name '{1}'." },
TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2214, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'." },
TypeParameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2215, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'." },
TypeParameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2216, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'." },
TypeParameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2217, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'." },
TypeParameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2218, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'." },
TypeParameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2: { code: 2219, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported function has or is using name '{1}' from private module '{2}'." },
TypeParameter_0_of_exported_class_has_or_is_using_private_name_1: { code: 2220, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported class has or is using private name '{1}'." },
TypeParameter_0_of_exported_interface_has_or_is_using_private_name_1: { code: 2221, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported interface has or is using private name '{1}'." },
TypeParameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2: { code: 2222, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported class has or is using name '{1}' from private module '{2}'." },
TypeParameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2: { code: 2223, category: DiagnosticCategory.Error, key: "TypeParameter '{0}' of exported interface 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

@@ -414,6 +414,70 @@
"category": "Error",
"code": 2023
},
"TypeParameter '{0}' of constructor signature from exported interface has or is using private name '{1}'.": {
"category": "Error",
"code": 2208
},
"TypeParameter '{0}' of call signature from exported interface has or is using private name '{1}'.": {
"category": "Error",
"code": 2209
},
"TypeParameter '{0}' of public static method from exported class has or is using private name '{1}'.": {
"category": "Error",
"code": 2210
},
"TypeParameter '{0}' of public method from exported class has or is using private name '{1}'.": {
"category": "Error",
"code": 2211
},
"TypeParameter '{0}' of method from exported interface has or is using private name '{1}'.": {
"category": "Error",
"code": 2212
},
"TypeParameter '{0}' of exported function has or is using private name '{1}'.": {
"category": "Error",
"code": 2213
},
"TypeParameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'.": {
"category": "Error",
"code": 2214
},
"TypeParameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'.": {
"category": "Error",
"code": 2215
},
"TypeParameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'.": {
"category": "Error",
"code": 2216
},
"TypeParameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'.": {
"category": "Error",
"code": 2217
},
"TypeParameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'.": {
"category": "Error",
"code": 2218
},
"TypeParameter '{0}' of exported function has or is using name '{1}' from private module '{2}'.": {
"category": "Error",
"code": 2219
},
"TypeParameter '{0}' of exported class has or is using private name '{1}'.": {
"category": "Error",
"code": 2220
},
"TypeParameter '{0}' of exported interface has or is using private name '{1}'.": {
"category": "Error",
"code": 2221
},
"TypeParameter '{0}' of exported class has or is using name '{1}' from private module '{2}'.": {
"category": "Error",
"code": 2222
},
"TypeParameter '{0}' of exported interface has or is using name '{1}' from private module '{2}'.": {
"category": "Error",
"code": 2223
},
"'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.": {
"category": "Error",
"code": 2068

View File

@@ -2011,10 +2011,76 @@ module ts {
function emitTypeParameters(typeParameters: TypeParameterDeclaration[]) {
function emitTypeParameter(node: TypeParameterDeclaration) {
function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
// TODO(shkamat) Cannot access name errors
var diagnosticMessage: DiagnosticMessage;
switch (node.parent.kind) {
case SyntaxKind.ClassDeclaration:
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
Diagnostics.TypeParameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.TypeParameter_0_of_exported_class_has_or_is_using_private_name_1;
break;
case SyntaxKind.InterfaceDeclaration:
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
Diagnostics.TypeParameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.TypeParameter_0_of_exported_interface_has_or_is_using_private_name_1;
break;
case SyntaxKind.ConstructSignature:
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
Diagnostics.TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
break;
case SyntaxKind.CallSignature:
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
Diagnostics.TypeParameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.TypeParameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
break;
case SyntaxKind.Method:
if (node.parent.flags & NodeFlags.Static) {
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
Diagnostics.TypeParameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.TypeParameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
}
else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) {
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
Diagnostics.TypeParameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.TypeParameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
}
else {
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
Diagnostics.TypeParameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.TypeParameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
}
break;
case SyntaxKind.FunctionDeclaration:
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
Diagnostics.TypeParameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 :
Diagnostics.TypeParameter_0_of_exported_function_has_or_is_using_private_name_1;
break;
default:
Debug.fail("This is unknown parent for type parameter: " + SyntaxKind[node.parent.kind]);
}
return {
diagnosticMessage: diagnosticMessage,
errorNode: node,
typeName: node.name
}
}
emitSourceTextOfNode(node.name);
if (node.constraint) {
write(" extends ");
getSymbolVisibilityDiagnosticMessage = getTypeParameterConstraintVisibilityError;
resolver.writeTypeAtLocation(node.constraint, enclosingDeclaration, TypeFormatFlags.None, writer);
// TODO(shkamat) This is just till we get rest of the error reporting up
getSymbolVisibilityDiagnosticMessage = undefined;
}
}
@@ -2076,6 +2142,8 @@ module ts {
}
getSymbolVisibilityDiagnosticMessage = getHeritageClauseVisibilityError;
resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.WriteArrayAsGenericType, writer);
// TODO(shkamat) This is just till we get rest of the error reporting up
getSymbolVisibilityDiagnosticMessage = undefined;
}
if (typeReferences) {