-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Use type annotations from arguments in let rec #12315
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The patch looks correct to me, and I agree that it is a reasonable extension of the current behavior.
(Is the absence of a Changes entry intentional?)
Error: This expression has type int but an expression was expected of type | ||
string | ||
|}] | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you include a case of optional argument, to make sure that this is handled correctly?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Nope, just hadn't written it yet. |
e93a382
to
d6f3c6c
Compare
I fear that the merge of #12210 broke the new test. Sorry about this collision. |
d6f3c6c
to
155690a
Compare
I rebased the PR (by force-pushing to the remote branch) to the new testsuite output. |
Thanks for rebasing! |
When typing
let rec
expressions, the compiler 'approximates' the type of each binding, allowing it to use information about each binding during typechecking. For instance, in alet rec
of functions, it knows the arity of each definition early, allowing it to produce partial application warnings for mutually recursive functions.Currently, type annotations on function parameters are ignored during this approximation. This delays typechecking errors, often in a confusing way. This patch makes approximation use these type annotations. As well as improving errors, this also makes type-based disambiguation work in more cases, for instance:
With this patch, the above typechecks, because the compiler knows that
g
acceptsM.t
before typing the body off
.