Skip to content

Compiler reports used before assigned after try...finally block #12205

Closed
@HerringtonDarkholme

Description

@HerringtonDarkholme

TypeScript Version: nightly (2.1.0-dev.20161112), --stricNullChecks

Note: this code compiles under 2.0.9

Code

// @strictNullChecks
declare function openFile(): void
declare function closeFile(): void
declare function someOperation(): {}

var result: {}
openFile()
try {
  result = someOperation()
} finally {
  closeFile()
}

result // error here

Expected behavior:

The code should compile. As #9260 (comment) goes, the try ... finally ... is a grammatical construct. If someOperation breaks the control flow, code after try-finally block will not be reachable. So result after block must be assigned.

Actual behavior:

Error as commented.

Related issues:
I have found a lot flow related issues. But they are more about closure/function declaration than try-catch-finally. So I think this is not a duplicate.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugA bug in TypeScriptFixedA PR has been merged for this issue

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions