Issue errors for all circular type parameter constraints

This commit is contained in:
Anders Hejlsberg 2019-02-26 12:39:01 -08:00
parent fb0dcd4987
commit ede6b9a5cb
2 changed files with 19 additions and 4 deletions

View File

@ -7577,7 +7577,19 @@ namespace ts {
constraintDepth++;
let result = computeBaseConstraint(getSimplifiedType(t));
constraintDepth--;
if (!popTypeResolution() || nonTerminating) {
if (!popTypeResolution()) {
if (t.flags & TypeFlags.TypeParameter) {
const errorNode = getConstraintDeclaration(<TypeParameter>t);
if (errorNode) {
const diagnostic = error(errorNode, Diagnostics.Type_parameter_0_has_a_circular_constraint, typeToString(t));
if (currentNode && !isNodeDescendantOf(errorNode, currentNode) && !isNodeDescendantOf(currentNode, errorNode)) {
addRelatedInfo(diagnostic, createDiagnosticForNode(currentNode, Diagnostics.Circularity_originates_in_type_at_this_location));
}
}
}
result = circularConstraintType;
}
if (nonTerminating) {
result = circularConstraintType;
}
t.immediateBaseConstraint = result || noConstraintType;
@ -23475,9 +23487,8 @@ namespace ts {
checkSourceElement(node.constraint);
checkSourceElement(node.default);
const typeParameter = getDeclaredTypeOfTypeParameter(getSymbolOfNode(node));
if (!hasNonCircularBaseConstraint(typeParameter)) {
error(getEffectiveConstraintOfTypeParameter(node), Diagnostics.Type_parameter_0_has_a_circular_constraint, typeToString(typeParameter));
}
// Resolve base constraint to reveal circularity errors
getBaseConstraintOfType(typeParameter);
if (!hasNonCircularTypeParameterDefault(typeParameter)) {
error(node.default, Diagnostics.Type_parameter_0_has_a_circular_default, typeToString(typeParameter));
}

View File

@ -2589,6 +2589,10 @@
"category": "Error",
"code": 2750
},
"Circularity originates in type at this location.": {
"category": "Error",
"code": 2751
},
"Import declaration '{0}' is using private name '{1}'.": {
"category": "Error",