In short, if we have a variable used within a function, say:
# some variable x is declared and used a bunch
f(x)
We can use type inference to get the type of x even if we don't assign it a type above.
However, if we already know the type of x, then at most the check stage should check that it is a valid argument to the function.
If we instead match it directly, we can get weird situations if the function signature specifies the argument is a union.
Then the unification stage will also state that x is this union, which can lead to erroneous output:
Example
def f(x: {Int, Str}) -> Int => 10
def x := 10
f(x)
Will give the following:
# function definition here
x: Union[int, str] = 10
f(x)
While we expect:
x: int = 10
f(x)
Code quality
Move propagate logic to Constraint, moving logic away from Name which shouldn't be there.
Added Tests
WIP: Argument types still leak out unnecessarily in tests:
Summary
In short, if we have a variable used within a function, say:
We can use type inference to get the type of x even if we don't assign it a type above. However, if we already know the type of x, then at most the check stage should check that it is a valid argument to the function. If we instead match it directly, we can get weird situations if the function signature specifies the argument is a union. Then the unification stage will also state that
x
is this union, which can lead to erroneous output:Example
Will give the following:
While we expect:
Code quality
Move propagate logic to Constraint, moving logic away from
Name
which shouldn't be there.Added Tests
WIP: Argument types still leak out unnecessarily in tests: