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

Type Inference for If statements #22

Closed
MichaReiser opened this issue Apr 4, 2016 · 0 comments
Closed

Type Inference for If statements #22

MichaReiser opened this issue Apr 4, 2016 · 0 comments

Comments

@MichaReiser
Copy link
Owner

Add support for IF-Statements to the type Inference algorithm. The following edge cases need to be
supported, as they are widely used.

Type inference needs to be branch specific

function (x) {
  if (typeof(x) === 'string') { // inside the branch x is of type string
    x = parseInt(x, 10); // type changes from string to int
  }
  return x * x; // the type of x is always number
}

The possible types of a variable after an if statement need to be the most common between all branches

if (y > 10) {
  x = 10;  // x is typeof number
else {
  x = null; // x is typeof Null
}

return x + 10; // x is typeof Maybe<number>
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

1 participant