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 involving skolem variables #2102

Closed
byorgey opened this issue Aug 9, 2024 · 0 comments · Fixed by #2340
Closed

Improve error messages involving skolem variables #2102

byorgey opened this issue Aug 9, 2024 · 0 comments · Fixed by #2340
Assignees
Labels
C-Moderate Effort Should take a moderate amount of time to address. L-Error reporting Reporting language or runtime errors to the player. L-Type inference The process of inferring the type of a Swarm expression. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. Z-User Experience This issue seeks to make the game more enjoyable to play.

Comments

@byorgey
Copy link
Member

byorgey commented Aug 9, 2024

There are two kinds of error messages we could get involving skolem variables.

  • We can simply get a type mismatch when we try to unify a skolem variable with something else. However, the current error is confusing since it references a made-up variable. For example:

    > def f : a -> a = \x. 3 end
    1:22: Type mismatch:
      From context, expected `3` to have type `s1`,
      but it actually has type `Int`
    
      - While checking the definition of f
    

    It would be better if the error said something about polymorphism and mentioned the type variable a. This might require keeping track of a mapping between generated skolem variables and type variables in the polymorphic type.

  • When a skolem variable escapes, the error message is even worse since the error explicitly mentions the word "skolem":

    > \f. (f:forall a. a -> a) 3
    1:5: Skolem variable s3 would escape its scope
    

    This case is more obscure and probably won't happen very much (especially once we fix Strange type checking error "Skolem variable would escape its scope" #2101), but it would still be nice to come up with a better error message that at least hints at what the problem might be.

@byorgey byorgey added Z-User Experience This issue seeks to make the game more enjoyable to play. C-Moderate Effort Should take a moderate amount of time to address. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. L-Type inference The process of inferring the type of a Swarm expression. L-Error reporting Reporting language or runtime errors to the player. labels Aug 9, 2024
@byorgey byorgey self-assigned this Feb 4, 2025
@mergify mergify bot closed this as completed in #2340 Mar 10, 2025
mergify bot pushed a commit that referenced this issue Mar 10, 2025
…2340)

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-Moderate Effort Should take a moderate amount of time to address. L-Error reporting Reporting language or runtime errors to the player. L-Type inference The process of inferring the type of a Swarm expression. S-Nice to have The bug fix or feature would be nice but doesn't currently have much negative impact. Z-User Experience This issue seeks to make the game more enjoyable to play.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant