Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@dolio
Copy link
Contributor

@dolio dolio commented Aug 6, 2025

In definitions like:

foo : '{g} a -> ()
foo th =
  !th
  foo th

we end up in a situation where we can't actually solve to the type '{g} a ->{g} (). The reason is that we make up the existential variable immediately so that we can type check the recursive function with a specified type of '{g} a ->{e} (). The g that e needs to be solved to ends up later in the context, so the solution is not allowed.

This change introduces a new error message that detects this situation and suggests an ability set for the signature. There was a previous 'pretty' error message that had been disabled for this situation, but it was fairly uninformative, and might have been just as useless as the ugly error message we were currently displaying.

Fixes #5655 and #5025

Note: this problem only occurs with recursive definitions. We actually take steps to avoid this problem in other situations (do existentializeArrows after unbinding the foralls). But this isn't an option for recursive let, because the control flow adds the existentials and type signatures to the context before checking any definitions in the binding group.

In definitions like:

  foo : '{g} a -> ()
  foo th =
    !th
    foo th

we end up in a situation where we can't actually solve to the type
`'{g} a ->{g} ()`. The reason is that we make up the existential
variable immediately so that we can type check the recursive function
with a specified type of `'{g} a ->{e} ()`. The `g` that `e` needs to
be solved to ends up later in the context, so the solution is not
allowed.

This change introduces a new error message that detects this situation
and suggests an ability set for the signature. There was a previous
'pretty' error message that had been disabled for this situation, but
it was fairly uninformative, and might have been just as useless as
the ugly error message we were currently displaying.
@dolio dolio requested review from aryairani and pchiusano August 6, 2025 00:49
@ceedubs
Copy link
Contributor

ceedubs commented Aug 6, 2025

Nice! Might be helpful to capture it in a failing block in a transcript to avoid accidental regressions to the error message.

@aryairani
Copy link
Contributor

Nice! Might be helpful to capture it in a failing block in a transcript to avoid accidental regressions to the error message.

Yes please — for me it's mainly to have an example of each error message in the transcript output somewhere.

@dolio
Copy link
Contributor Author

dolio commented Aug 7, 2025

Added.

Copy link
Contributor

@aryairani aryairani left a comment

Choose a reason for hiding this comment

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

Thanks!

@aryairani aryairani merged commit 7867a49 into trunk Aug 7, 2025
31 checks passed
@aryairani aryairani deleted the topic/ability-instantiation-error branch August 7, 2025 20:52
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.

Badly formatted type error in this case

3 participants