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

Better type error messages when there are unification variables involved #1318

Merged
merged 19 commits into from Jun 11, 2023

Conversation

byorgey
Copy link
Member

@byorgey byorgey commented Jun 9, 2023

Say things like "expecting xyz to be a function" instead of "expecting xyz to have type u3 -> u4". Closes #1313.

Co-authored-by: Restyled.io <commits@restyled.io>
Copy link
Member

@xsebek xsebek left a comment

Choose a reason for hiding this comment

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

Those new error messages sure sound more human! 👍 I also like more context in type checking, even if that comes at the cost of some heavy lifting. 😄

"definition with wrong result"
( process
"def m : int -> int -> int = \\x. \\y. {3} end"
"1:37: Type mismatch:\n From context, expected `{3}` to have type `int`,\n but it is actually a delayed expression"
Copy link
Member

Choose a reason for hiding this comment

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

Could you please add a test case for two functions?

It seems to be handled based on the cmd test case above, but it would be nice to be sure we don't say:

expected f to be a function, but it is actually a function!

Copy link
Member Author

Choose a reason for hiding this comment

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

I added a couple test cases involving incompatible functions to show what happens. We will never say "expected f to be a function, but it is actually a function", for two reasons: first, if we are trying to unify two types and they are both function types, then we will proceed to unifying their input and output types, so we would never fail at the point where we have two function types. Second, we only say "blah is a function" when it specifically has a type of the form u1 -> u2 where u1 and u2 are unification variables. Any two such types will be guaranteed to be unifiable.

@byorgey byorgey added the merge me Trigger the merge process of the Pull request. label Jun 11, 2023
@mergify mergify bot merged commit a85318e into main Jun 11, 2023
9 checks passed
@mergify mergify bot deleted the feature/english-type-errors branch June 11, 2023 02:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge me Trigger the merge process of the Pull request.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Use more descriptive English terms in type error messages
2 participants