@@ -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>();
@@ -4449,14 +4450,22 @@ namespace ts {
4449
4450
function getTypeOfInstantiatedSymbol(symbol: Symbol): Type {
4450
4451
const links = getSymbolLinks(symbol);
4451
4452
if (!links.type) {
4452
- if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
4453
- return unknownType;
4453
+ if (symbolInstantiationDepth === 100) {
4454
+ error(symbol.valueDeclaration, Diagnostics.Generic_type_instantiation_is_excessively_deep_and_possibly_infinite);
4455
+ links.type = unknownType;
4454
4456
}
4455
- let type = instantiateType(getTypeOfSymbol(links.target), links.mapper);
4456
- if (!popTypeResolution()) {
4457
- type = reportCircularityError(symbol);
4457
+ else {
4458
+ if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
4459
+ return unknownType;
4460
+ }
4461
+ symbolInstantiationDepth++;
4462
+ let type = instantiateType(getTypeOfSymbol(links.target), links.mapper);
4463
+ symbolInstantiationDepth--;
4464
+ if (!popTypeResolution()) {
4465
+ type = reportCircularityError(symbol);
4466
+ }
4467
+ links.type = type;
4458
4468
}
4459
- links.type = type;
4460
4469
}
4461
4470
return links.type;
4462
4471
}
@@ -7266,8 +7275,9 @@ namespace ts {
7266
7275
else {
7267
7276
error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType));
7268
7277
}
7278
+ return unknownType;
7269
7279
}
7270
- return unknownType ;
7280
+ return anyType ;
7271
7281
}
7272
7282
7273
7283
function getIndexedAccessForMappedType(type: MappedType, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode) {
0 commit comments