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

Fix #256, Improve checking for null type #263

Merged
merged 1 commit into from
Oct 22, 2015
Merged

Fix #256, Improve checking for null type #263

merged 1 commit into from
Oct 22, 2015

Conversation

EliasC
Copy link
Contributor

@EliasC EliasC commented Oct 21, 2015

This commit should fix most cases where the null type leaks to the
backend (which causes a crash) by catching it in the typechecker
instead. It generalizes checking for null by introducing an auxilary
function typecheckNotNull which is called when an expression is used
where no additional type information could coerce the null type to a
reference type (for example the right hand sides of the declarations of
a let or the body of a closure). It unifies all earlier error messages
of type "Cannot infer type of null valued expression".

It's usage is not always obvious. For example, when typechecking a
sequence, all expressions but the last should be checked for the null
type, but the last one should not, as it's actual type could be inferred
from the context of the sequence.

There is also added support for propagating an inferred result type. For
example, in the function

def foo() : Foo{
  let x = 42 in
    while x < 0 {
      x = x - 1;
      null;
    }
  }

we know that the null should be a Foo from the result type.

This commit should fix most cases where the null type leaks to the
backend (which causes a crash) by catching it in the typechecker
instead. It generalizes checking for `null` by introducing an auxilary
function `typecheckNotNull` which is called when an expression is used
where no additional type information could coerce the null type to a
reference type (for example the right hand sides of the declarations of
a let or the body of a closure). It unifies all earlier error messages
of type "Cannot infer type of null valued expression".

It's usage is not always obvious. For example, when typechecking a
sequence, all expressions but the last should be checked for the null
type, but the last one should not, as it's actual type could be inferred
from the context of the sequence.

There is also added support for propagating an inferred result type. For
example, in the function
```
def foo() : Foo{
  let x = 42 in
    while x < 0 {
      x = x - 1;
      null;
    }
  }
```
we know that the `null` should be a `Foo` from the result type.
kaeluka pushed a commit that referenced this pull request Oct 22, 2015
Fix #256, Improve checking for null type
@kaeluka kaeluka merged commit aa3ce11 into parapluu:master Oct 22, 2015
@EliasC EliasC deleted the fix/null branch November 20, 2015 10:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants