Debug assert on parent rebind, mitigate circularity in symbol access checking (#22282)

* Assert that symbol parents are never rebound to different parents

* mitigate circularities in symbol accessibility checking
This commit is contained in:
Wesley Wigham
2018-03-01 16:49:42 -08:00
committed by GitHub
parent f6418c0d30
commit 10e3b73330
2 changed files with 22 additions and 5 deletions

View File

@@ -427,7 +427,12 @@ namespace ts {
}
addDeclarationToSymbol(symbol, node, includes);
symbol.parent = parent;
if (symbol.parent) {
Debug.assert(symbol.parent === parent, "Existing symbol parent should match new one");
}
else {
symbol.parent = parent;
}
return symbol;
}

View File

@@ -2470,12 +2470,19 @@ namespace ts {
return rightMeaning === SymbolFlags.Value ? SymbolFlags.Value : SymbolFlags.Namespace;
}
function getAccessibleSymbolChain(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, useOnlyExternalAliasing: boolean): Symbol[] | undefined {
function getAccessibleSymbolChain(symbol: Symbol, enclosingDeclaration: Node | undefined, meaning: SymbolFlags, useOnlyExternalAliasing: boolean, visitedSymbolTablesMap: Map<SymbolTable[]> = createMap()): Symbol[] | undefined {
if (!(symbol && !isPropertyOrMethodDeclarationSymbol(symbol))) {
return undefined;
}
const visitedSymbolTables: SymbolTable[] = [];
const id = "" + getSymbolId(symbol);
let visitedSymbolTables: SymbolTable[];
if (visitedSymbolTablesMap.has(id)) {
visitedSymbolTables = visitedSymbolTablesMap.get(id);
}
else {
visitedSymbolTablesMap.set(id, visitedSymbolTables = []);
}
return forEachSymbolTableInScope(enclosingDeclaration, getAccessibleSymbolChainFromSymbolTable);
/**
@@ -2495,7 +2502,7 @@ namespace ts {
// If the symbol is equivalent and doesn't need further qualification, this symbol is accessible
return !needsQualification(symbolFromSymbolTable, enclosingDeclaration, meaning) ||
// If symbol needs qualification, make sure that parent is accessible, if it is then this symbol is accessible too
!!getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing);
!!getAccessibleSymbolChain(symbolFromSymbolTable.parent, enclosingDeclaration, getQualifiedLeftMeaning(meaning), useOnlyExternalAliasing, visitedSymbolTablesMap);
}
function isAccessible(symbolFromSymbolTable: Symbol, resolvedAliasSymbol?: Symbol, ignoreQualification?: boolean) {
@@ -5445,7 +5452,12 @@ namespace ts {
}
addDeclarationToLateBoundSymbol(lateSymbol, decl, symbolFlags);
lateSymbol.parent = parent;
if (lateSymbol.parent) {
Debug.assert(lateSymbol.parent === parent, "Existing symbol parent should match new one");
}
else {
lateSymbol.parent = parent;
}
return links.resolvedSymbol = lateSymbol;
}
}