encore icon indicating copy to clipboard operation
encore copied to clipboard

Improved type inference

Open supercooldave opened this issue 7 years ago • 4 comments

This PR relaxes the type checking in the compiler dealing with unknown information (BottomType), which arises for instance in expressions like Nothing where the parameter to Maybe[_] is not provided nor can be inferred from the context. This PR permits such code to compile because the presence of BottomType does not affect the compilation.

Some previously failing tests now pass.

The key test is in regressions/836.enc because this PR builds directly upon the PR that fixed that issue (#841).

Also, fixes #792

supercooldave avatar Jul 04 '17 13:07 supercooldave

@EliasC The situation you refer to involves multiple different statements, as opposed to a single expression. Checking of bottomness doesn't span different statements. Of the top of my head, I'm not sure how best to handle this. Perhaps the error message could include some better hints, such as where good places to add the type annotations are.

supercooldave avatar Jul 13 '17 11:07 supercooldave

What I'm proposing is to disallow val x = Nothing and give the error about type annotations there, but still allow e.g. match Nothing with .... If you assign Nothing to a variable, chances are very high that you are planning to re-assign it, which will lead to an error. We should therefore catch this error as early as possible.

EliasC avatar Jul 13 '17 11:07 EliasC

@EliasC Sounds complicated to check and awfully specific. Would [Nothing] be allowed? Or is the assignment of a bottom-typed value disallowed?

supercooldave avatar Jul 13 '17 11:07 supercooldave

I'll be more clear:

An assignment where the right-hand side has a type that contains the bottom type should not be allowed without type annotations. Similarly, I think that closure whose body has a type that contains the bottom type should not be allowed without type annotations. All other usages of the bottom type can be allowed.

EliasC avatar Jul 13 '17 11:07 EliasC