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

Use original variable names in error messages about Skolem variables #2340

Merged
merged 4 commits into from
Mar 10, 2025

Conversation

byorgey
Copy link
Member

@byorgey byorgey commented Mar 9, 2025

Each type variable now carries two variable names: one, the original, user-supplied name of the type variable, and another, the (potentially different) current freshly generated name. These can diverge specifically in the case that we skolemize a user-supplied polymorphic type. We use the second name for all comparisons, but the first name when pretty-printing.

For example, def f : a -> a = \x. 3 end used to generate an error message saying something like "expected 3 to have type s1 ; it now says "expected 3 to have type a".

Closes #2102. That issue also talks about improving the error message that says "skolem variable would escape its scope", but at the moment I can't even find a way to get that error message to be generated at all, so I propose to not worry about it for now.

There is one specific situation where this can be confusing, when one type variable is shadowed by another with the same name. For example:

> def f : a -> (a * Int) = \\x. let g : forall a. a * Int = (x, 3) in g end
1:59: Type mismatch:\n  From context, expected `x` to have type `a`,\n  but it actually has type `a`

Not sure whether it's worth doing anything about this; open to suggestions.

@byorgey byorgey requested review from xsebek and kostmo March 10, 2025 03:03
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.

@byorgey this is great! I remember that any error messages with skolemized type names were hard for me to understand, but this should fix that in most cases. 👍

Regarding the same name, I take it that the type names do not keep the source span like values do?
If they did, the error messages could continue with "a declared at source.sw: line 12 char 42" and similarly for the other a.

@byorgey
Copy link
Member Author

byorgey commented Mar 10, 2025

I take it that the type names do not keep the source span like values do?

Yeah, they don't, but they probably should! That would be a bigger change though. Filed as #2343.

@byorgey byorgey added the merge me Trigger the merge process of the Pull request. label Mar 10, 2025
@mergify mergify bot merged commit 98bc1c5 into main Mar 10, 2025
12 checks passed
@mergify mergify bot deleted the byorgey/feature/skolem-msgs branch March 10, 2025 19:46
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.

Improve error messages involving skolem variables
2 participants