Fix type inference for recursive let bindings #2187
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.
Fixes #2186.
When inferring the type of a recursive let binding with no provided type signature, we generate a unification variable to stand for its type, then infer the type of the body with the unification variable in the context. Finally, we must unify the generated unification variable with the inferred type. However, previously, we were doing this final unification with a direct call to
=:=
(which simply returns anEither
) and discarding the result, which meant that we would simply ignore it when they failed to unify.This PR replaces the bad call to
=:=
with a call tounify
, and also makes the=:=
import qualified to make it less likely that we will ever call=:=
directly like this again.This would only have ever caused a problem with (1) a recursive function definition (2) with no type annotation (3) with a type error (4) specifically in one of the recursive applications. Apparently no one had ever done all of 1-4 at the same time before; @xsebek was the lucky winner. 😄