Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
HerringtonDarkholme opened this issue Nov 13, 2016 · 0 comments
Closed
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue

Comments

@HerringtonDarkholme
Copy link
Contributor

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.

@mhegazy mhegazy added the Bug A bug in TypeScript label Nov 13, 2016
@mhegazy mhegazy added this to the TypeScript 2.1.3 milestone Nov 13, 2016
@mhegazy mhegazy modified the milestones: TypeScript 2.2, TypeScript 2.1.3 Nov 17, 2016
@mhegazy mhegazy added the Fixed A PR has been merged for this issue label Feb 2, 2017
@vladima vladima closed this as completed Feb 13, 2017
@microsoft microsoft locked and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug A bug in TypeScript Fixed A PR has been merged for this issue
Projects
None yet
Development

No branches or pull requests

3 participants