Fix control flow analysis for nested try-catch-finally statements (#39399)

* Fix control flow analysis for nested try-catch-finally statements

* Add tests
This commit is contained in:
Anders Hejlsberg
2020-07-03 09:51:01 -07:00
committed by GitHub
parent fd8ca520ab
commit 2fe2f88047
6 changed files with 607 additions and 0 deletions

View File

@@ -1241,6 +1241,11 @@ namespace ts {
if (currentReturnTarget && returnLabel.antecedents) {
addAntecedent(currentReturnTarget, createReduceLabel(finallyLabel, returnLabel.antecedents, currentFlow));
}
// If we have an outer exception target (i.e. a containing try-finally or try-catch-finally), add a
// control flow that goes back through the finally blok and back through each possible exception source.
if (currentExceptionTarget && exceptionLabel.antecedents) {
addAntecedent(currentExceptionTarget, createReduceLabel(finallyLabel, exceptionLabel.antecedents, currentFlow));
}
// If the end of the finally block is reachable, but the end of the try and catch blocks are not,
// convert the current flow to unreachable. For example, 'try { return 1; } finally { ... }' should
// result in an unreachable current control flow.