-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Give hints about existential types appearing in error messages #12622
Conversation
Naïve question: do we need to introduce another kind of type variable, |
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.
(Only very superficial review comments for now.)
The Also worth pointing out that this PR isn't adding these generated abstract types with |
I like the feature, and the code is pleasantly not-too-invasive. If we had a type-checker expert at hand they should review the design, but if they are busy I would feel confident approving after a review for code quality -- I have done a pass already and don't expect that there is much more for me to discuss. |
I tend to agree that this change overall reduces noise: On the one hand, we lose some information locality because the name I am wondering if later we could show the constructor definition in the hint to gives an even more useful context. A small remark, the manual description of the existential nomenclature should be updated. In particular, we are left with only three categories now that we always name anonymous constructor argument types. |
Comments addressed and Changes entry added |
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.
I find the revised implementation (and documentation) satisfactory. Approved.
I would think of "squashing" the commits together as they are not split in independent changes currently.
A tiny amount of information is lost here: originally the names combined the constructor name, and the name of the existential variable inside the definition. Here the hint only gives the constructor name. |
We could add it to give an error like:
normally it would be pretty redundant, but I guess in some cases it would be more like:
where the two names aren't quite identical, and so perhaps useful. |
How easy would it be to always reuse the variable name as prefix, with the counter as suffix? |
That's already what happens: we use the variable name in the constructor definition if it exists when we choose the existential variable name at instantiation, and the type printer only adds a numerical suffix in case of collisions: type any = Any: 'any * 'more -> any
type other = Other: 'any * 'more -> other
type variant = Variant: 'any * 'more -> variant
let f (Any(x,y)) (Other(a,_)) (Variant(r,_)) = (x,y) = (r,a)
|
Ah, so I don't think that any change is necessary? |
I see, since all the variables were named |
This PR changes the names of existential types from things like
$Foo_'a
to just$a
and instead adds an explicit hint describing where$a
came from. For instance, this message from the testsuite:becomes:
It does this by broadening the
abstract_reason
type to atype_origin
type that describes where a type has come from, and uses that to annotate existential types in the environment with the constructor they have come from.The printing is done in the same way as the existing hints about conflicting names. Personally, I think these don't have the best indentation -- it would be better if the hint was unindented -- but I can't see an obvious way to achieve that and it's as much a problem with the conflict hints as with the new ones.