@@ -47,6 +47,7 @@ namespace ts {
47
47
48
48
let typeCount = 0;
49
49
let symbolCount = 0;
50
+ let symbolInstantiationDepth = 0;
50
51
51
52
const emptyArray: any[] = [];
52
53
const emptySymbols = createMap<Symbol>();
@@ -4440,14 +4441,22 @@ namespace ts {
4440
4441
function getTypeOfInstantiatedSymbol(symbol: Symbol): Type {
4441
4442
const links = getSymbolLinks(symbol);
4442
4443
if (!links.type) {
4443
- if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
4444
- return unknownType;
4444
+ if (symbolInstantiationDepth === 100) {
4445
+ error(symbol.valueDeclaration, Diagnostics.Generic_type_instantiation_is_excessively_deep_and_possibly_infinite);
4446
+ links.type = unknownType;
4445
4447
}
4446
- let type = instantiateType(getTypeOfSymbol(links.target), links.mapper);
4447
- if (!popTypeResolution()) {
4448
- type = reportCircularityError(symbol);
4448
+ else {
4449
+ if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
4450
+ return unknownType;
4451
+ }
4452
+ symbolInstantiationDepth++;
4453
+ let type = instantiateType(getTypeOfSymbol(links.target), links.mapper);
4454
+ symbolInstantiationDepth--;
4455
+ if (!popTypeResolution()) {
4456
+ type = reportCircularityError(symbol);
4457
+ }
4458
+ links.type = type;
4449
4459
}
4450
- links.type = type;
4451
4460
}
4452
4461
return links.type;
4453
4462
}
@@ -7257,8 +7266,9 @@ namespace ts {
7257
7266
else {
7258
7267
error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType));
7259
7268
}
7269
+ return unknownType;
7260
7270
}
7261
- return unknownType ;
7271
+ return anyType ;
7262
7272
}
7263
7273
7264
7274
function getIndexedAccessForMappedType(type: MappedType, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode) {
0 commit comments