Skip to content
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

Improve error messages for polymorphic tail parametricity violations #1320

Merged
merged 1 commit into from
May 25, 2023

Conversation

matthew-healy
Copy link
Contributor

Previously, if we had a type whose return value contained a polymorphic tail and we tried to return a value which was not statically known to be in the return type, we would see a type mismatch error with an "invented" type name (e.g. a) to represent "an arbitrary type in the tail".

This made it unclear where the problem was, and didn't give any real direction on how to fix the problem.

This commit raises a specific error in this case, which informs users that the type they've tried to return is not guaranteed to exist in the polymorphic tail. We also now pass around a var kind with type errors related to constant mismatches, so we can print a representation of the tail type (e.g. [| ; x |]) instead of inventing phantom type names for errors.

Fixes #1316.

@github-actions github-actions bot temporarily deployed to pull request May 25, 2023 08:45 Inactive
@github-actions github-actions bot temporarily deployed to pull request May 25, 2023 08:54 Inactive
Copy link
Contributor

@vkleen vkleen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The general approach looks like a net improvement to me. I'm just not happy with the error message 😅 Values don't exist in a type, they have types or maybe they're compatible with types if subtyping is allowed. Maybe

"values of type {violating_type} are not guaranteed to be compatible with a polymorphic {tail_king} `{tail}`"

The record tail error message referencing the type { } also feels a bit weird to me, but I don't think that's introduced in this PR.

@matthew-healy
Copy link
Contributor Author

@vkleen Totally happy to change the error message. I wasn't happy with it either, but figured it was better to just do something & then bikeshed it in the PR. 😁 Your suggestion is much better.

Previously, if we had a type whose return value contained a polymorphic
tail and we tried to return a value which was not statically known
to be in the return type, we would see a type mismatch error with an
"invented" type name (e.g. `a`) to represent "an arbitrary type in the
tail".

This made it unclear where the problem was, and didn't give any real
direction on how to fix the problem.

This commit raises a specific error in this case, which informs users
that the type they've tried to return is not guaranteed to exist in the
polymorphic tail. We also now pass around a var kind with type errors
related to constant mismatches, so we can print a representation of the
tail type (e.g. `[| ; x |]`) instead of inventing phantom type names
for errors.

Fixes #1316.
@matthew-healy matthew-healy marked this pull request as ready for review May 25, 2023 10:42
@github-actions github-actions bot temporarily deployed to pull request May 25, 2023 10:45 Inactive
@matthew-healy matthew-healy added this pull request to the merge queue May 25, 2023
Merged via the queue into master with commit 808b984 May 25, 2023
@matthew-healy matthew-healy deleted the fix/poly-tail-type-error branch May 25, 2023 11:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Poor error message in polymorphic tail type error
2 participants