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
Add specific explanation for unification errors involving functions of type unit -> _ #1505
Conversation
This looks like a step in the right direction. I have few minor remarks; Also, looking at the tests, I am wondering if it would not be better to group all tests in one file rather than four? Similarly, it would be nice to write a comment explaining why the On a more subjective matter, |
1530624
to
bb7e76e
Compare
Good point, I changed the message to "Did you forget...".
This was just to keep track of the offline remark by @garrigue ; here this example is actually not problematic AFAICT.
I merged the tests to a single file, and added such a comment. |
bb7e76e
to
2a9f252
Compare
I like this change! Looking at the implementation (which is fairly straightforward) I wondered two things:
|
Is there a way of checking whether T and T' can unify, without actually unifying them? (which triggers side effects) Otherwise I'm a bit reluctant to do an unification and mutate the types at this stage, even though this is perhaps OK since we're already in failure mode.
I've never seen or used a one-constructor, no argument type that is not unit, so I'm not sure it's worth the hassle. |
Instantiate to get a copy of the type with fresh type variables, then unify.
Pretty sure you have seen at least one: |
That would only copy the generalised parts of the type, which I'm assuming isn't the whole type here. The right way to do this is to use the backtracking support in |
7d75eff
to
4179faf
Compare
4179faf
to
46ede41
Compare
Just added a test that exercises the unification+backtracking check. |
46ede41
to
8db7de2
Compare
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.
Armaël and myself went into a rabbit hole to understand whether Unify _
was really the only kind of exception that Ctype.unify
could raise; the implementation seems to also raise Unification_recursive_abbrev
, but actually it looks like dead code -- and other parts of typecore also only catch Unify anyway.
With this detail out of the way, I believe the PR is correct.
|
This is another small change extracted from PR #102 by @charguer . Its purpose is to provide suggestions for the common mistake of forgetting to pass
()
as argument to functions e.g.print_newline
. The patch has also be extended to handle the symmetric situation where a value is passed instead of a thunk (and thus afun () ->
is missing).@garrigue mentioned offline that there could be an issue in interaction with optional arguments (in which case we would disable the message in presence of functions with optional/labeled arguments) -- but I couldn't reproduce the issue. (cf the example we noted)