Limit symbol instantiations to a maximum depth of 100

This commit is contained in:
Anders Hejlsberg 2017-04-04 14:48:57 -07:00
parent 1c649433bd
commit 6909574973
2 changed files with 21 additions and 7 deletions

View File

@ -47,6 +47,7 @@ namespace ts {
let typeCount = 0;
let symbolCount = 0;
let symbolInstantiationDepth = 0;
const emptyArray: any[] = [];
const emptySymbols = createMap<Symbol>();
@ -4440,14 +4441,22 @@ namespace ts {
function getTypeOfInstantiatedSymbol(symbol: Symbol): Type {
const links = getSymbolLinks(symbol);
if (!links.type) {
if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
return unknownType;
if (symbolInstantiationDepth === 100) {
error(symbol.valueDeclaration, Diagnostics.Generic_type_instantiation_is_excessively_deep_and_possibly_infinite);
links.type = unknownType;
}
let type = instantiateType(getTypeOfSymbol(links.target), links.mapper);
if (!popTypeResolution()) {
type = reportCircularityError(symbol);
else {
if (!pushTypeResolution(symbol, TypeSystemPropertyName.Type)) {
return unknownType;
}
symbolInstantiationDepth++;
let type = instantiateType(getTypeOfSymbol(links.target), links.mapper);
symbolInstantiationDepth--;
if (!popTypeResolution()) {
type = reportCircularityError(symbol);
}
links.type = type;
}
links.type = type;
}
return links.type;
}
@ -7257,8 +7266,9 @@ namespace ts {
else {
error(indexNode, Diagnostics.Type_0_cannot_be_used_as_an_index_type, typeToString(indexType));
}
return unknownType;
}
return unknownType;
return anyType;
}
function getIndexedAccessForMappedType(type: MappedType, indexType: Type, accessNode?: ElementAccessExpression | IndexedAccessTypeNode) {

View File

@ -1827,6 +1827,10 @@
"category": "Error",
"code": 2549
},
"Generic type instantiation is excessively deep and possibly infinite.": {
"category": "Error",
"code": 2550
},
"JSX element attributes type '{0}' may not be a union type.": {
"category": "Error",
"code": 2600