Skip to content

Commit 9fd95fc

Browse files
committed
Report errors if the type parameter uses constraint that is using private type/module
Fixes #86
1 parent 09ec1bb commit 9fd95fc

18 files changed

+3259
-245
lines changed

src/compiler/diagnosticInformationMap.generated.ts

+16
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,22 @@ module ts {
105105
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}'." },
106106
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}'." },
107107
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}'." },
108+
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}'." },
109+
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}'." },
110+
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}'." },
111+
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}'." },
112+
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}'." },
113+
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}'." },
114+
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}'." },
115+
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}'." },
116+
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}'." },
117+
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}'." },
118+
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}'." },
119+
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}'." },
120+
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}'." },
121+
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}'." },
122+
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}'." },
123+
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}'." },
108124
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." },
109125
Multiple_constructor_implementations_are_not_allowed: { code: 2070, category: DiagnosticCategory.Error, key: "Multiple constructor implementations are not allowed." },
110126
A_class_may_only_implement_another_class_or_interface: { code: 2074, category: DiagnosticCategory.Error, key: "A class may only implement another class or interface." },

src/compiler/diagnosticMessages.json

+64
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,70 @@
414414
"category": "Error",
415415
"code": 2023
416416
},
417+
"TypeParameter '{0}' of constructor signature from exported interface has or is using private name '{1}'.": {
418+
"category": "Error",
419+
"code": 2208
420+
},
421+
"TypeParameter '{0}' of call signature from exported interface has or is using private name '{1}'.": {
422+
"category": "Error",
423+
"code": 2209
424+
},
425+
"TypeParameter '{0}' of public static method from exported class has or is using private name '{1}'.": {
426+
"category": "Error",
427+
"code": 2210
428+
},
429+
"TypeParameter '{0}' of public method from exported class has or is using private name '{1}'.": {
430+
"category": "Error",
431+
"code": 2211
432+
},
433+
"TypeParameter '{0}' of method from exported interface has or is using private name '{1}'.": {
434+
"category": "Error",
435+
"code": 2212
436+
},
437+
"TypeParameter '{0}' of exported function has or is using private name '{1}'.": {
438+
"category": "Error",
439+
"code": 2213
440+
},
441+
"TypeParameter '{0}' of constructor signature from exported interface has or is using name '{1}' from private module '{2}'.": {
442+
"category": "Error",
443+
"code": 2214
444+
},
445+
"TypeParameter '{0}' of call signature from exported interface has or is using name '{1}' from private module '{2}'.": {
446+
"category": "Error",
447+
"code": 2215
448+
},
449+
"TypeParameter '{0}' of public static method from exported class has or is using name '{1}' from private module '{2}'.": {
450+
"category": "Error",
451+
"code": 2216
452+
},
453+
"TypeParameter '{0}' of public method from exported class has or is using name '{1}' from private module '{2}'.": {
454+
"category": "Error",
455+
"code": 2217
456+
},
457+
"TypeParameter '{0}' of method from exported interface has or is using name '{1}' from private module '{2}'.": {
458+
"category": "Error",
459+
"code": 2218
460+
},
461+
"TypeParameter '{0}' of exported function has or is using name '{1}' from private module '{2}'.": {
462+
"category": "Error",
463+
"code": 2219
464+
},
465+
"TypeParameter '{0}' of exported class has or is using private name '{1}'.": {
466+
"category": "Error",
467+
"code": 2220
468+
},
469+
"TypeParameter '{0}' of exported interface has or is using private name '{1}'.": {
470+
"category": "Error",
471+
"code": 2221
472+
},
473+
"TypeParameter '{0}' of exported class has or is using name '{1}' from private module '{2}'.": {
474+
"category": "Error",
475+
"code": 2222
476+
},
477+
"TypeParameter '{0}' of exported interface has or is using name '{1}' from private module '{2}'.": {
478+
"category": "Error",
479+
"code": 2223
480+
},
417481
"'new T[]' cannot be used to create an array. Use 'new Array<T>()' instead.": {
418482
"category": "Error",
419483
"code": 2068

src/compiler/emitter.ts

+68
Original file line numberDiff line numberDiff line change
@@ -2011,10 +2011,76 @@ module ts {
20112011

20122012
function emitTypeParameters(typeParameters: TypeParameterDeclaration[]) {
20132013
function emitTypeParameter(node: TypeParameterDeclaration) {
2014+
function getTypeParameterConstraintVisibilityError(symbolAccesibilityResult: SymbolAccessiblityResult) {
2015+
// TODO(shkamat) Cannot access name errors
2016+
var diagnosticMessage: DiagnosticMessage;
2017+
switch (node.parent.kind) {
2018+
case SyntaxKind.ClassDeclaration:
2019+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2020+
Diagnostics.TypeParameter_0_of_exported_class_has_or_is_using_name_1_from_private_module_2 :
2021+
Diagnostics.TypeParameter_0_of_exported_class_has_or_is_using_private_name_1;
2022+
break;
2023+
2024+
case SyntaxKind.InterfaceDeclaration:
2025+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2026+
Diagnostics.TypeParameter_0_of_exported_interface_has_or_is_using_name_1_from_private_module_2 :
2027+
Diagnostics.TypeParameter_0_of_exported_interface_has_or_is_using_private_name_1;
2028+
break;
2029+
2030+
case SyntaxKind.ConstructSignature:
2031+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2032+
Diagnostics.TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
2033+
Diagnostics.TypeParameter_0_of_constructor_signature_from_exported_interface_has_or_is_using_private_name_1;
2034+
break;
2035+
2036+
case SyntaxKind.CallSignature:
2037+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2038+
Diagnostics.TypeParameter_0_of_call_signature_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
2039+
Diagnostics.TypeParameter_0_of_call_signature_from_exported_interface_has_or_is_using_private_name_1;
2040+
break;
2041+
2042+
case SyntaxKind.Method:
2043+
if (node.parent.flags & NodeFlags.Static) {
2044+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2045+
Diagnostics.TypeParameter_0_of_public_static_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
2046+
Diagnostics.TypeParameter_0_of_public_static_method_from_exported_class_has_or_is_using_private_name_1;
2047+
}
2048+
else if (node.parent.parent.kind === SyntaxKind.ClassDeclaration) {
2049+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2050+
Diagnostics.TypeParameter_0_of_public_method_from_exported_class_has_or_is_using_name_1_from_private_module_2 :
2051+
Diagnostics.TypeParameter_0_of_public_method_from_exported_class_has_or_is_using_private_name_1;
2052+
}
2053+
else {
2054+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2055+
Diagnostics.TypeParameter_0_of_method_from_exported_interface_has_or_is_using_name_1_from_private_module_2 :
2056+
Diagnostics.TypeParameter_0_of_method_from_exported_interface_has_or_is_using_private_name_1;
2057+
}
2058+
break;
2059+
2060+
case SyntaxKind.FunctionDeclaration:
2061+
diagnosticMessage = symbolAccesibilityResult.errorModuleName ?
2062+
Diagnostics.TypeParameter_0_of_exported_function_has_or_is_using_name_1_from_private_module_2 :
2063+
Diagnostics.TypeParameter_0_of_exported_function_has_or_is_using_private_name_1;
2064+
break;
2065+
2066+
default:
2067+
Debug.fail("This is unknown parent for type parameter: " + SyntaxKind[node.parent.kind]);
2068+
}
2069+
2070+
return {
2071+
diagnosticMessage: diagnosticMessage,
2072+
errorNode: node,
2073+
typeName: node.name
2074+
}
2075+
}
2076+
20142077
emitSourceTextOfNode(node.name);
20152078
if (node.constraint) {
20162079
write(" extends ");
2080+
getSymbolVisibilityDiagnosticMessage = getTypeParameterConstraintVisibilityError;
20172081
resolver.writeTypeAtLocation(node.constraint, enclosingDeclaration, TypeFormatFlags.None, writer);
2082+
// TODO(shkamat) This is just till we get rest of the error reporting up
2083+
getSymbolVisibilityDiagnosticMessage = undefined;
20182084
}
20192085
}
20202086

@@ -2076,6 +2142,8 @@ module ts {
20762142
}
20772143
getSymbolVisibilityDiagnosticMessage = getHeritageClauseVisibilityError;
20782144
resolver.writeTypeAtLocation(node, enclosingDeclaration, TypeFormatFlags.WriteArrayAsGenericType, writer);
2145+
// TODO(shkamat) This is just till we get rest of the error reporting up
2146+
getSymbolVisibilityDiagnosticMessage = undefined;
20792147
}
20802148

20812149
if (typeReferences) {

tests/baselines/reference/privacyTypeParameterOfFunction.errors.txt

-136
This file was deleted.

0 commit comments

Comments
 (0)