Skip to content

Commit 1074ddd

Browse files
committed
Modify flow loop cache key to include all inputs
1 parent d865ea7 commit 1074ddd

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/compiler/checker.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15418,21 +15418,21 @@ namespace ts {
1541815418
// The result is undefined if the reference isn't a dotted name. We prefix nodes
1541915419
// occurring in an apparent type position with '@' because the control flow type
1542015420
// of such nodes may be based on the apparent type instead of the declared type.
15421-
function getFlowCacheKey(node: Node): string | undefined {
15421+
function getFlowCacheKey(node: Node, declaredType: Type, initialType: Type, flowContainer: Node | undefined): string | undefined {
1542215422
switch (node.kind) {
1542315423
case SyntaxKind.Identifier:
1542415424
const symbol = getResolvedSymbol(<Identifier>node);
15425-
return symbol !== unknownSymbol ? (isConstraintPosition(node) ? "@" : "") + getSymbolId(symbol) : undefined;
15425+
return symbol !== unknownSymbol ? `${flowContainer ? getNodeId(flowContainer) : "-1"}|${getTypeId(declaredType)}|${getTypeId(initialType)}|${isConstraintPosition(node) ? "@" : ""}${getSymbolId(symbol)}` : undefined;
1542615426
case SyntaxKind.ThisKeyword:
1542715427
return "0";
1542815428
case SyntaxKind.NonNullExpression:
1542915429
case SyntaxKind.ParenthesizedExpression:
15430-
return getFlowCacheKey((<NonNullExpression | ParenthesizedExpression>node).expression);
15430+
return getFlowCacheKey((<NonNullExpression | ParenthesizedExpression>node).expression, declaredType, initialType, flowContainer);
1543115431
case SyntaxKind.PropertyAccessExpression:
1543215432
case SyntaxKind.ElementAccessExpression:
1543315433
const propName = getAccessedPropertyName(<AccessExpression>node);
1543415434
if (propName !== undefined) {
15435-
const key = getFlowCacheKey((<AccessExpression>node).expression);
15435+
const key = getFlowCacheKey((<AccessExpression>node).expression, declaredType, initialType, flowContainer);
1543615436
return key && key + "." + propName;
1543715437
}
1543815438
}
@@ -16367,7 +16367,7 @@ namespace ts {
1636716367
const id = getFlowNodeId(flow);
1636816368
const cache = flowLoopCaches[id] || (flowLoopCaches[id] = createMap<Type>());
1636916369
if (!key) {
16370-
key = getFlowCacheKey(reference);
16370+
key = getFlowCacheKey(reference, declaredType, initialType, flowContainer);
1637116371
// No cache key is generated when binding patterns are in unnarrowable situations
1637216372
if (!key) {
1637316373
return declaredType;

0 commit comments

Comments
 (0)