Open schungx opened 1 year ago
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.
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
}
Right now assignments do not do anything to the type of the variable:
On a straight assignment to a lone variable, that variable should take on the type of the expression.