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

Flow thinks conditional throwing leaves variables uninitialized #13

Closed
sophiebits opened this issue Nov 18, 2014 · 2 comments
Closed

Flow thinks conditional throwing leaves variables uninitialized #13

sophiebits opened this issue Nov 18, 2014 · 2 comments
Assignees

Comments

@sophiebits
Copy link
Contributor

If I have code like the following

/* @flow */

function f(x: number): number {
    var y;
    if (x < 0) {
        throw new Error();
    } else {
        y = Math.sqrt(x);
    }
    return y;
}

then Flow complains that y (undefined) is incompatible with number because it doesn't get properly initialized. If you add y = 0; on the line after the throw then no errors are thrown – ideally Flow would recognize the semantics of the throw statement here and know that the return statement isn't reached in the case that an error is thrown.

@avikchaudhuri
Copy link
Contributor

Agreed. Will fix.

@gabelevi
Copy link
Contributor

This was fixed awhile ago, sorry that we neglected to close the issue!

jeffmo pushed a commit to jeffmo/flow that referenced this issue Jul 31, 2015
Wrapping/unwrapping handlers properly.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants