From 1074dddfb38a3ddc343bc287756241b6a34d91ec Mon Sep 17 00:00:00 2001 From: Wesley Wigham Date: Thu, 25 Apr 2019 16:28:18 -0700 Subject: [PATCH] Modify flow loop cache key to include all inputs --- src/compiler/checker.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 473b41ccec5e2..579f93851f9b7 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -15418,21 +15418,21 @@ namespace ts { // The result is undefined if the reference isn't a dotted name. We prefix nodes // occurring in an apparent type position with '@' because the control flow type // of such nodes may be based on the apparent type instead of the declared type. - function getFlowCacheKey(node: Node): string | undefined { + function getFlowCacheKey(node: Node, declaredType: Type, initialType: Type, flowContainer: Node | undefined): string | undefined { switch (node.kind) { case SyntaxKind.Identifier: const symbol = getResolvedSymbol(node); - return symbol !== unknownSymbol ? (isConstraintPosition(node) ? "@" : "") + getSymbolId(symbol) : undefined; + return symbol !== unknownSymbol ? `${flowContainer ? getNodeId(flowContainer) : "-1"}|${getTypeId(declaredType)}|${getTypeId(initialType)}|${isConstraintPosition(node) ? "@" : ""}${getSymbolId(symbol)}` : undefined; case SyntaxKind.ThisKeyword: return "0"; case SyntaxKind.NonNullExpression: case SyntaxKind.ParenthesizedExpression: - return getFlowCacheKey((node).expression); + return getFlowCacheKey((node).expression, declaredType, initialType, flowContainer); case SyntaxKind.PropertyAccessExpression: case SyntaxKind.ElementAccessExpression: const propName = getAccessedPropertyName(node); if (propName !== undefined) { - const key = getFlowCacheKey((node).expression); + const key = getFlowCacheKey((node).expression, declaredType, initialType, flowContainer); return key && key + "." + propName; } } @@ -16367,7 +16367,7 @@ namespace ts { const id = getFlowNodeId(flow); const cache = flowLoopCaches[id] || (flowLoopCaches[id] = createMap()); if (!key) { - key = getFlowCacheKey(reference); + key = getFlowCacheKey(reference, declaredType, initialType, flowContainer); // No cache key is generated when binding patterns are in unnarrowable situations if (!key) { return declaredType;