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 typing #104

Open
schungx opened this issue Sep 5, 2022 · 2 comments
Open

Flow typing #104

schungx opened this issue Sep 5, 2022 · 2 comments
Labels
A-HIR Area: HIR E-Hard feature T-Types Related to the type system

Comments

@schungx
Copy link
Collaborator

schungx commented Sep 5, 2022

Right now assignments do not do anything to the type of the variable:

let a = 42;    // a is int

a = true;    // a is still int

On a straight assignment to a lone variable, that variable should take on the type of the expression.

@tamasfe tamasfe changed the title Propagate types during assignment Flow typing Sep 5, 2022
@tamasfe tamasfe added feature E-Hard A-HIR Area: HIR T-Types Related to the type system labels Sep 5, 2022
@tamasfe
Copy link
Member

tamasfe commented Sep 5, 2022

This should be done alongside proper flow type-inference.

let a = 1;

if true {
  a = true;
  // a is bool here
}

// a is still int here

In the meantime we can probably just create a union of all possible types, however I'm not sure how useful that is.

@schungx
Copy link
Collaborator Author

schungx commented Sep 6, 2022

In the meantime we can probably just create a union of all possible types, however I'm not sure how useful that is.

I believe a union of possible types would be very very useful, because in a lot of cases the choices are really not too many, and control flow down the road may start restricting them.

For example:

let a = 1;   // a is int

if condition {
  a = true;  // a is bool
}

// a is int | bool

do_something(a);  // only do_something(int) or do_something(bool) match

if type_of(a) == "int" {
    // a is int here
} else {
    // a is bool here, essentially (int | bool) - int
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-HIR Area: HIR E-Hard feature T-Types Related to the type system
Projects
None yet
Development

No branches or pull requests

2 participants