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

Fix confusing disambiguation errors appearing instead of type errors #768

Merged
merged 2 commits into from
Jan 9, 2025

Conversation

AltGr
Copy link
Contributor

@AltGr AltGr commented Jan 8, 2025

Closes #749 ;
the PR also has a patch that greatly improves real disambiguation errors when they happen.

The issue was actually with the way we attempt to gather multiple typing errors: this can get us in an inconsistent state after the first error, and any non-delayed exception raised at that point (including internal inconsistency compiler errors) would break out... and hide all delayed exceptions.

This is visible in test array/bad/type_error_in_filter.catala_en which would raise a Cannot resolve typing error because assumptions of the typer are no longer guaranteed.

The behaviour implemented here is to print the errors that have been delayed, and actually hide the non-delayed error instead (it seems safer to assume, in general, that it is a consequence of an inconsistent state, rather than the opposite. We could put it back when in debug mode if we ever find cases where it would have been useful).

AltGr added 2 commits January 8, 2025 17:15
When a non-delayed error happens after delayed errors, these should take
precedence and be raised rather than ignored. Indeed, it's often a consequence
of delayed errors.

This happened in the disambiguation phase where a type inconsistency would be
skipped, leading to a failure to disambiguate, and only the latter was printed
resulting in a puzzling error.
@AltGr AltGr requested a review from vincent-botbol January 8, 2025 16:30
Comment on lines +534 to +552
let result =
match f () with
| r -> fun () -> r
| exception (CompilerError _ as e) ->
let bt = Printexc.get_raw_backtrace () in
fun () -> Printexc.raise_with_backtrace e bt
| exception e -> raise e
in
match global_errors.errors with
| None -> error ~internal:true "intertwined delayed error scope"
| Some [] ->
global_errors.errors <- None;
result ()
| Some [err] ->
global_errors.errors <- None;
raise (CompilerError err)
| Some errs ->
global_errors.errors <- None;
raise e
raise (CompilerErrors (List.rev errs))
Copy link
Contributor

Choose a reason for hiding this comment

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

This could use a little comment to understand what's going on :)

Copy link
Contributor

@vincent-botbol vincent-botbol left a comment

Choose a reason for hiding this comment

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

Indeed, sorry about that..

@AltGr
Copy link
Contributor Author

AltGr commented Jan 8, 2025

@vincent-botbol haha don't worry you certainly have as much on my account ;)

@AltGr AltGr merged commit 66c5df5 into master Jan 9, 2025
5 checks passed
@AltGr AltGr deleted the fix-disamb-err branch January 9, 2025 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Failures to typecheck during disambiguation / any types
3 participants