Skip to content

Improve semantic error messages#1552

Merged
WardBrian merged 4 commits intomasterfrom
improve-semantic-error-messages
Sep 19, 2025
Merged

Improve semantic error messages#1552
WardBrian merged 4 commits intomasterfrom
improve-semantic-error-messages

Conversation

@WardBrian
Copy link
Copy Markdown
Member

This is the first piece of something like #1549, but for the semantic errors this time. For now, just some minor edits to the wording of a few messaging and some bikeshed-y moving of errors between the categories that the Semantic_error module uses internally.

I also updated the internal definition of Semantic_error.t and Syntax_error.t to 'lift' the location up. This makes it look a bit more like Warning.t and saves some duplicated type information

Submission Checklist

  • Run unit tests
  • Documentation
    • If a user-facing facing change was made, the documentation PR is here:
    • OR, no user-facing changes were made

Release notes

Updated the error messages for type errors to be more consistent with one another.

Copyright and Licensing

By submitting this pull request, the copyright holder is agreeing to
license the submitted work under the BSD 3-clause license (https://opensource.org/licenses/BSD-3-Clause)

@WardBrian WardBrian requested a review from nhuurre September 18, 2025 19:48
@codecov
Copy link
Copy Markdown

codecov bot commented Sep 18, 2025

Codecov Report

❌ Patch coverage is 98.69281% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.25%. Comparing base (837912e) to head (31d6245).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
src/frontend/Semantic_error.ml 98.49% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1552      +/-   ##
==========================================
- Coverage   90.25%   90.25%   -0.01%     
==========================================
  Files          64       64              
  Lines        9926     9914      -12     
==========================================
- Hits         8959     8948      -11     
+ Misses        967      966       -1     
Files with missing lines Coverage Δ
src/frontend/Errors.ml 100.00% <100.00%> (ø)
src/frontend/SignatureMismatch.ml 86.61% <100.00%> (+0.05%) ⬆️
src/frontend/Syntax_error.ml 96.66% <100.00%> (-0.08%) ⬇️
src/frontend/Semantic_error.ml 95.56% <98.49%> (+0.23%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Comment on lines +620 to +626
type err =
| TypeError of TypeError.t
| IdentifierError of IdentifierError.t
| ExpressionError of ExpressionError.t
| StatementError of StatementError.t

type t = Location_span.t * err
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

It's a bit unsightly that Semantic_error.t is now an opaque tuple (opaque since users are expected to call our location instead fst directly) and pp only prints half of it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

pp only printed half of of the actual content of the type before, it was just one level deeper.

I played around with having pp do the entire job, but it isn't clear where the shared code between Semantic_error and Syntax_error for printing the context would go. It can't stay in Errors, since that would introduce a circular dependency, and it can't be moved entirely into Middle.Location, since it relies on Frontend.Include_files

@WardBrian WardBrian merged commit 35ec0c1 into master Sep 19, 2025
3 checks passed
@WardBrian WardBrian deleted the improve-semantic-error-messages branch September 19, 2025 13:53
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.

2 participants