Track tuple type recursion in inferFromObjectTypes (#37479)

* Track recursive tuple types in inferFromObjectTypes

* Add regression test
This commit is contained in:
Anders Hejlsberg
2020-03-19 14:05:33 -07:00
committed by GitHub
parent 7e07a2b5d1
commit e15a9fb3a8
6 changed files with 209 additions and 6 deletions

View File

@@ -18131,7 +18131,7 @@ namespace ts {
}
function inferTypes(inferences: InferenceInfo[], originalSource: Type, originalTarget: Type, priority: InferencePriority = 0, contravariant = false) {
let symbolStack: Symbol[];
let symbolOrTypeStack: (Symbol | Type)[];
let visited: Map<number>;
let bivariant = false;
let propagationType: Type;
@@ -18570,15 +18570,15 @@ namespace ts {
// its symbol with the instance side which would lead to false positives.
const isNonConstructorObject = target.flags & TypeFlags.Object &&
!(getObjectFlags(target) & ObjectFlags.Anonymous && target.symbol && target.symbol.flags & SymbolFlags.Class);
const symbol = isNonConstructorObject ? target.symbol : undefined;
if (symbol) {
if (contains(symbolStack, symbol)) {
const symbolOrType = isNonConstructorObject ? isTupleType(target) ? target.target : target.symbol : undefined;
if (symbolOrType) {
if (contains(symbolOrTypeStack, symbolOrType)) {
inferencePriority = InferencePriority.Circularity;
return;
}
(symbolStack || (symbolStack = [])).push(symbol);
(symbolOrTypeStack || (symbolOrTypeStack = [])).push(symbolOrType);
inferFromObjectTypesWorker(source, target);
symbolStack.pop();
symbolOrTypeStack.pop();
}
else {
inferFromObjectTypesWorker(source, target);