Merge pull request #8295 from Microsoft/anyDefaultsToAny

Variable of type any has initial type any in control flow analysis
This commit is contained in:
Anders Hejlsberg 2016-04-25 21:41:30 -07:00
commit da0197527f
5 changed files with 72 additions and 1 deletions

View File

@ -7972,7 +7972,7 @@ namespace ts {
return type;
}
const declaration = localOrExportSymbol.valueDeclaration;
const defaultsToDeclaredType = !strictNullChecks || !declaration ||
const defaultsToDeclaredType = !strictNullChecks || type.flags & TypeFlags.Any || !declaration ||
declaration.kind === SyntaxKind.Parameter || isInAmbientContext(declaration) ||
getContainingFunctionOrModule(declaration) !== getContainingFunctionOrModule(node);
if (defaultsToDeclaredType && !(type.flags & TypeFlags.Narrowable)) {

View File

@ -0,0 +1,22 @@
//// [defaultOfAnyInStrictNullChecks.ts]
// Regression test for #8295
function foo() {
try {
}
catch (e) {
let s = e.message;
}
}
//// [defaultOfAnyInStrictNullChecks.js]
// Regression test for #8295
function foo() {
try {
}
catch (e) {
var s = e.message;
}
}

View File

@ -0,0 +1,18 @@
=== tests/cases/compiler/defaultOfAnyInStrictNullChecks.ts ===
// Regression test for #8295
function foo() {
>foo : Symbol(foo, Decl(defaultOfAnyInStrictNullChecks.ts, 0, 0))
try {
}
catch (e) {
>e : Symbol(e, Decl(defaultOfAnyInStrictNullChecks.ts, 6, 11))
let s = e.message;
>s : Symbol(s, Decl(defaultOfAnyInStrictNullChecks.ts, 7, 11))
>e : Symbol(e, Decl(defaultOfAnyInStrictNullChecks.ts, 6, 11))
}
}

View File

@ -0,0 +1,20 @@
=== tests/cases/compiler/defaultOfAnyInStrictNullChecks.ts ===
// Regression test for #8295
function foo() {
>foo : () => void
try {
}
catch (e) {
>e : any
let s = e.message;
>s : any
>e.message : any
>e : any
>message : any
}
}

View File

@ -0,0 +1,11 @@
// @strictNullChecks: true
// Regression test for #8295
function foo() {
try {
}
catch (e) {
let s = e.message;
}
}