From a52805f641f0f3edf7f48040bfb48b9b8daabc29 Mon Sep 17 00:00:00 2001 From: Nathan Shively-Sanders Date: Fri, 9 Dec 2016 10:50:14 -0800 Subject: [PATCH] Use checkExpression in checkSpreadExpression Not checkExpressionCached. checkExpressionCached ignores ongoing control flow analysis, which causes the following loop to make the compiler recur infinitely: ```ts let a = [] for (const x of []) { a = [...a] } ``` --- src/compiler/checker.ts | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index 778e31b9c5b..a81cf64fa15 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -11252,13 +11252,7 @@ namespace ts { } function checkSpreadExpression(node: SpreadElement, contextualMapper?: TypeMapper): Type { - // It is usually not safe to call checkExpressionCached if we can be contextually typing. - // You can tell that we are contextually typing because of the contextualMapper parameter. - // While it is true that a spread element can have a contextual type, it does not do anything - // with this type. It is neither affected by it, nor does it propagate it to its operand. - // So the fact that contextualMapper is passed is not important, because the operand of a spread - // element is not contextually typed. - const arrayOrIterableType = checkExpressionCached(node.expression, contextualMapper); + const arrayOrIterableType = checkExpression(node.expression, contextualMapper); return checkIteratedTypeOrElementType(arrayOrIterableType, node.expression, /*allowStringInput*/ false); }