Conversation
EliasC
left a comment
There was a problem hiding this comment.
I see the point of this and the changes are straightforward, but I'm wondering if we're optimising for toy programs rather than "real" code? For example, the following expression now compiles (which makes sense)
match Nothing with
Nothing => 42
end
but at the same time, the following function (still) does not compile and arguably gives a worse error message than before:
fun lookup[k : Eq[k], v](key : k, arr : [(k, v)]) : Maybe[v]
var elem = Nothing
for e <- arr do
if e.0.eq(key) then
elem = Just(e.1)
end
end
return elem
end
Not enough information to infer the type.
Try adding more type information.
In expression:
Just(e.1)
In expression:
elem = Just(e.1)
The function is fixed by adding type annotations, not where the typechecker is pointing, but where elem is declared. Before this PR, the typechecker would indeed fail at the declaration site.
Does it make sense to require type annotations for, say, variables and functions whose values (bodies) contain a bottom typed value?
|
@EliasC The situation you refer to involves multiple different statements, as opposed to a single expression. Checking of bottomness doesn't span different statements. |
| import Data.List | ||
| import Data.Maybe | ||
| import Text.Printf (printf) | ||
| import Debug.Trace |
There was a problem hiding this comment.
We will most likely need this again :)
There was a problem hiding this comment.
I thought we were finished with tracing. My bad.
|
What I'm proposing is to disallow |
|
@EliasC Sounds complicated to check and awfully specific. Would |
|
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. |
This PR relaxes the type checking in the compiler dealing with unknown information (
BottomType), which arises for instance in expressions likeNothingwhere the parameter toMaybe[_]is not provided nor can be inferred from the context. This PR permits such code to compile because the presence ofBottomTypedoes not affect the compilation.Some previously failing tests now pass.
The key test is in
regressions/836.encbecause this PR builds directly upon the PR that fixed that issue (#841).Also, fixes #792