Skip to content

Types leak out of function definition #475

Description

@JSAbrahams

Summary

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)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions