From 6e72858dbc885b334efe3f08dfdf0bac7bac782f Mon Sep 17 00:00:00 2001 From: Anders Hejlsberg Date: Fri, 9 Sep 2016 10:05:06 -0700 Subject: [PATCH] Assume outer variables are always initialized in control flow analysis --- src/compiler/checker.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/compiler/checker.ts b/src/compiler/checker.ts index f5eb12a419e..a8b6557e3c3 100644 --- a/src/compiler/checker.ts +++ b/src/compiler/checker.ts @@ -8920,6 +8920,7 @@ namespace ts { const isParameter = getRootDeclaration(declaration).kind === SyntaxKind.Parameter; const declarationContainer = getControlFlowContainer(declaration); let flowContainer = getControlFlowContainer(node); + const isOuterVariable = flowContainer !== declarationContainer; // When the control flow originates in a function expression or arrow function and we are referencing // a const variable or parameter from an outer function, we extend the origin of the control flow // analysis to include the immediately enclosing function. @@ -8932,7 +8933,7 @@ namespace ts { // the entire control flow graph from the variable's declaration (i.e. when the flow container and // declaration container are the same). const assumeInitialized = !strictNullChecks || (type.flags & TypeFlags.Any) !== 0 || isParameter || - flowContainer !== declarationContainer || isInAmbientContext(declaration); + isOuterVariable || isInAmbientContext(declaration); const flowType = getFlowTypeOfReference(node, type, assumeInitialized, flowContainer); // A variable is considered uninitialized when it is possible to analyze the entire control flow graph // from declaration to use, and when the variable's declared type doesn't include undefined but the