Merge pull request #7246 from Microsoft/noImplicitReturnsWithProtectedBlocks

properly set reachable state after protected try\finally block
This commit is contained in:
Vladimir Matveev 2016-02-25 15:03:44 -08:00
commit 8074dbd046
11 changed files with 192 additions and 1 deletions

View File

@ -685,7 +685,7 @@ namespace ts {
// post catch/finally state is reachable if
// - post try state is reachable - control flow can fall out of try block
// - post catch state is reachable - control flow can fall out of catch block
currentReachabilityState = or(postTryState, postCatchState);
currentReachabilityState = n.catchClause ? or(postTryState, postCatchState) : postTryState;
}
function bindSwitchStatement(n: SwitchStatement): void {

View File

@ -0,0 +1,22 @@
//// [noImplicitReturnsWithProtectedBlocks1.ts]
declare function log(s: string): void;
declare function get(): number;
function main1() : number {
try {
return get();
}
finally {
log("in finally");
}
}
//// [noImplicitReturnsWithProtectedBlocks1.js]
function main1() {
try {
return get();
}
finally {
log("in finally");
}
}

View File

@ -0,0 +1,20 @@
=== tests/cases/compiler/noImplicitReturnsWithProtectedBlocks1.ts ===
declare function log(s: string): void;
>log : Symbol(log, Decl(noImplicitReturnsWithProtectedBlocks1.ts, 0, 0))
>s : Symbol(s, Decl(noImplicitReturnsWithProtectedBlocks1.ts, 0, 21))
declare function get(): number;
>get : Symbol(get, Decl(noImplicitReturnsWithProtectedBlocks1.ts, 0, 38))
function main1() : number {
>main1 : Symbol(main1, Decl(noImplicitReturnsWithProtectedBlocks1.ts, 1, 31))
try {
return get();
>get : Symbol(get, Decl(noImplicitReturnsWithProtectedBlocks1.ts, 0, 38))
}
finally {
log("in finally");
>log : Symbol(log, Decl(noImplicitReturnsWithProtectedBlocks1.ts, 0, 0))
}
}

View File

@ -0,0 +1,23 @@
=== tests/cases/compiler/noImplicitReturnsWithProtectedBlocks1.ts ===
declare function log(s: string): void;
>log : (s: string) => void
>s : string
declare function get(): number;
>get : () => number
function main1() : number {
>main1 : () => number
try {
return get();
>get() : number
>get : () => number
}
finally {
log("in finally");
>log("in finally") : void
>log : (s: string) => void
>"in finally" : string
}
}

View File

@ -0,0 +1,20 @@
tests/cases/compiler/noImplicitReturnsWithProtectedBlocks2.ts(4,20): error TS7030: Not all code paths return a value.
==== tests/cases/compiler/noImplicitReturnsWithProtectedBlocks2.ts (1 errors) ====
declare function log(s: string): void;
declare function get(): number;
function main1() : number {
~~~~~~
!!! error TS7030: Not all code paths return a value.
try {
return get();
}
catch(e) {
log("in catch");
}
finally {
log("in finally");
}
}

View File

@ -0,0 +1,28 @@
//// [noImplicitReturnsWithProtectedBlocks2.ts]
declare function log(s: string): void;
declare function get(): number;
function main1() : number {
try {
return get();
}
catch(e) {
log("in catch");
}
finally {
log("in finally");
}
}
//// [noImplicitReturnsWithProtectedBlocks2.js]
function main1() {
try {
return get();
}
catch (e) {
log("in catch");
}
finally {
log("in finally");
}
}

View File

@ -0,0 +1,17 @@
tests/cases/compiler/noImplicitReturnsWithProtectedBlocks3.ts(4,20): error TS7030: Not all code paths return a value.
==== tests/cases/compiler/noImplicitReturnsWithProtectedBlocks3.ts (1 errors) ====
declare function log(s: string): void;
declare function get(): number;
function main1() : number {
~~~~~~
!!! error TS7030: Not all code paths return a value.
try {
return get();
}
catch(e) {
log("in catch");
}
}

View File

@ -0,0 +1,22 @@
//// [noImplicitReturnsWithProtectedBlocks3.ts]
declare function log(s: string): void;
declare function get(): number;
function main1() : number {
try {
return get();
}
catch(e) {
log("in catch");
}
}
//// [noImplicitReturnsWithProtectedBlocks3.js]
function main1() {
try {
return get();
}
catch (e) {
log("in catch");
}
}

View File

@ -0,0 +1,12 @@
// @noImplicitReturns: true
declare function log(s: string): void;
declare function get(): number;
function main1() : number {
try {
return get();
}
finally {
log("in finally");
}
}

View File

@ -0,0 +1,15 @@
// @noImplicitReturns: true
declare function log(s: string): void;
declare function get(): number;
function main1() : number {
try {
return get();
}
catch(e) {
log("in catch");
}
finally {
log("in finally");
}
}

View File

@ -0,0 +1,12 @@
// @noImplicitReturns: true
declare function log(s: string): void;
declare function get(): number;
function main1() : number {
try {
return get();
}
catch(e) {
log("in catch");
}
}