Infer types of functions values based on names #400
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Previously, the type inference for creating function values with
(unstable-fn <name> [<partial arg>]*)
did not use the name. It would only use the context within which the function was created to infer the type of the function.This works fine if you only have one function sort defined or if always can infer it based on its calling location. However, I was noticing in my usages of
unstable-fn
I would often be passing another function reference as a partial arg. This means it would be hard for the type checker to figure out what type to use for these, so it would just give up and fail.In this PR, I extend the type inference for functions to use the string name. If it is a literal value that shows up during type checking and we can find it in the function table, we use this to help infer what the types are. We can then narrow down both the partial arg types and also make sure that the output and inputs to the function are the same as those of the
UnstableFn
sort. If not, then we know that this constructor won't match.The main change I had to do to implement this was to pass the
TypeInfo
into theaccept
method ofTypeConstraint
s, so that we could lookup the function name.I also had to add a new
ImpossibleConstraint
error for when a function is constructed with a string that doesn't match the function sort.