Add isDeeplyNestedType logic to getResolvedBaseConstraint (#40971)

* Add isDeeplyNestedType logic to getResolvedBaseConstraint

* Accept new baselines

* Add regression test

* Accept new baselines

* Fix lint issue
This commit is contained in:
Anders Hejlsberg
2020-10-07 05:50:06 -07:00
committed by GitHub
parent 14c731689e
commit f34220980b
8 changed files with 242 additions and 13 deletions

View File

@@ -10913,9 +10913,12 @@ namespace ts {
* circularly references the type variable.
*/
function getResolvedBaseConstraint(type: InstantiableType | UnionOrIntersectionType): Type {
if (type.resolvedBaseConstraint) {
return type.resolvedBaseConstraint;
}
let nonTerminating = false;
return type.resolvedBaseConstraint ||
(type.resolvedBaseConstraint = getTypeWithThisArgument(getImmediateBaseConstraint(type), type));
const stack: Type[] = [];
return type.resolvedBaseConstraint = getTypeWithThisArgument(getImmediateBaseConstraint(type), type);
function getImmediateBaseConstraint(t: Type): Type {
if (!t.immediateBaseConstraint) {
@@ -10932,9 +10935,14 @@ namespace ts {
nonTerminating = true;
return t.immediateBaseConstraint = noConstraintType;
}
constraintDepth++;
let result = computeBaseConstraint(getSimplifiedType(t, /*writing*/ false));
constraintDepth--;
let result;
if (!isDeeplyNestedType(t, stack, stack.length)) {
stack.push(t);
constraintDepth++;
result = computeBaseConstraint(getSimplifiedType(t, /*writing*/ false));
constraintDepth--;
stack.pop();
}
if (!popTypeResolution()) {
if (t.flags & TypeFlags.TypeParameter) {
const errorNode = getConstraintDeclaration(<TypeParameter>t);