Skip to content

Improve unclear error and warning messages#8460

Open
JonoPrest wants to merge 30 commits into
rescript-lang:masterfrom
JonoPrest:jono/improve-error-messages
Open

Improve unclear error and warning messages#8460
JonoPrest wants to merge 30 commits into
rescript-lang:masterfrom
JonoPrest:jono/improve-error-messages

Conversation

@JonoPrest
Copy link
Copy Markdown
Contributor

Summary

Improves error and warning messages that were unclear, terse, or used OCaml
terminology. Message text only, no behaviour changes; every change is covered
by an updated super_errors fixture.

Details

Follow-up to the super_errors fixture coverage work. After reviewing the
fixtures added in that work (including the ones flagged by @cknitt on #8432),
the changes group into:

  • The wording @cknitt flagged: non-function application, @return(*_to_opt),
    the @int/@as payload, and conflicting attributes.
  • Render @ correctly in FFI attribute messages, which printed %@ literally.
  • Use ReScript terms rather than OCaml ones: switch (not "match expression"),
    pattern (not "matching"), let rec (not let rec'), first-class module
    (not "packed module").
  • Grammar and clarity: subject-verb agreement, list grammar, singular/plural
    in the type-arity error, and dropping the OCaml-manual references from two
    warnings.
  • The conflicting-attributes error now names the attributes actually involved
    (e.g. @string, @int) instead of listing every possible one.
  • Report the real attribute name in the misplaced-@inline warning, which was
    leaking an internal inline1.

A few advanced type-system messages (variance, polymorphic-variant
present/conjunction) are left as-is; rewording them needs more care.

JonoPrest added 28 commits June 2, 2026 11:11
Saying "The function has type" right after "it's not a function" was
contradictory. Use "It has type" instead.
The old message was grammatically broken ("expect return type to be syntax
wise `_ option` for safety") and rendered `%@return` literally. State the
requirement plainly and show the option syntax.
"expect int literal" was terse and contextless. Name the attribute and
show the expected form.
"conflicting attributes" did not say which attributes conflict. List the
mutually-exclusive set (@string, @int, @ignore, @unwrap).
These messages used "%@" where they meant "@" (e.g. "%@string",
"%@unwrap", "conflicts with %@Val"). pp_print_string emits it literally, so
users saw "%@". Use "@" so the attribute name reads correctly.
Fix the "%@this" rendering and the broken grammar ("expect its pattern
variable to be simple form"). State what is required and why.
Capitalize and use a full sentence instead of "expect string literal "
(trailing space). Kept generic since it is shared by @as payloads and
@@directive.
Replace "expect int, string literal or json literal {json|text here|json}"
with a plain sentence.
Verified against the raise sites:

- @this (ast_uncurry_gen.ml): the self parameter must satisfy
  is_single_variable_pattern_conservative, i.e. a plain variable or `_`. A
  constant pattern also fails and `_` is allowed, so "not a destructured
  pattern" was imprecise. State the requirement positively.
- @return (ast_external_process.ml): `nullable` and `null_undefined_to_opt`
  trigger this too, not just `*_to_opt` directives, so describe the option
  requirement generically rather than naming the directive shape.
Replace the OCaml-style `let rec' quoting with `let rec`.
Warnings 52 and 57 pointed users to "manual section 8.5" of the OCaml
manual, which is irrelevant to ReScript. Also add a space after the comma
when listing ambiguous or-pattern variables.
List the supported directives instead of the terse "Not supported return
directive".
Duplicated_bs_as also fires for record fields (e.g. inline records) and
polymorphic-variant tags, not just variant cases, so the message should not
say "a variant case".
The misplaced-@inline warning hardcoded "inline1"/"inline2" as the
attribute name, leaking an internal distinction; the user wrote @inline. Use
the real attribute name.
Warnings 47/53/54 referred to attributes as "inline" / 'inline'; ReScript
messages elsewhere use the @-prefixed form (@as, @deriving, ...). Use @inline
etc. for consistency.
Conflict_attributes now carries the list of attributes involved, so the
message reports all of them (e.g. "@string, @int, @unwrap") instead of the
full set of every possible attribute.
"is not allowed in programs" was vague; type variable names cannot start
with an underscore.
"expects 1 argument(s), but is here applied to 2 argument(s)" -> proper
singular/plural and "is given".
- first-class module instead of "packed module"
- explain that a cross-module GADT constructor needs its module prefix
- explain the existential-in-pattern error and point to switch
Quote the name like the other polished messages (and the same message's
zero-argument branch already does).
@JonoPrest
Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector
Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@JonoPrest JonoPrest force-pushed the jono/improve-error-messages branch from 53f37dd to df15a5d Compare June 2, 2026 11:37
Errors are sentence-case; "unsupported predicates" and the consecutive-
statements syntax error started lowercase.
@JonoPrest JonoPrest force-pushed the jono/improve-error-messages branch from df15a5d to 4b6a19c Compare June 2, 2026 11:52
@codecov
Copy link
Copy Markdown

codecov Bot commented Jun 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.94%. Comparing base (7d96fe3) to head (386d81b).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8460   +/-   ##
=======================================
  Coverage   60.93%   60.94%           
=======================================
  Files         374      374           
  Lines       54039    54050   +11     
=======================================
+ Hits        32930    32942   +12     
+ Misses      21109    21108    -1     
Files with missing lines Coverage Δ
compiler/ext/warnings.ml 71.42% <100.00%> (ø)
compiler/frontend/ast_attributes.ml 80.32% <100.00%> (+1.01%) ⬆️
compiler/frontend/ast_external_process.ml 78.54% <ø> (ø)
compiler/frontend/bs_syntaxerr.ml 100.00% <100.00%> (ø)
compiler/ml/ast_untagged_variants.ml 83.67% <100.00%> (ø)
compiler/ml/rec_check.ml 49.76% <ø> (ø)
compiler/ml/translattribute.ml 72.41% <ø> (ø)
compiler/ml/translmod.ml 96.04% <ø> (ø)
compiler/ml/typecore.ml 86.00% <100.00%> (ø)
compiler/ml/typemod.ml 72.27% <ø> (ø)
... and 2 more
🚀 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.

@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Jun 2, 2026

Open in StackBlitz

rescript

npm i https://pkg.pr.new/rescript@8460

@rescript/darwin-arm64

npm i https://pkg.pr.new/@rescript/darwin-arm64@8460

@rescript/darwin-x64

npm i https://pkg.pr.new/@rescript/darwin-x64@8460

@rescript/linux-arm64

npm i https://pkg.pr.new/@rescript/linux-arm64@8460

@rescript/linux-x64

npm i https://pkg.pr.new/@rescript/linux-x64@8460

@rescript/runtime

npm i https://pkg.pr.new/@rescript/runtime@8460

@rescript/win32-x64

npm i https://pkg.pr.new/@rescript/win32-x64@8460

commit: 386d81b

- Add a fixture for a non-generic type applied to arguments (covers the
  zero-arity branch of the type-arity-mismatch message, and the plural case).
- Add an @ignore/@unwrap conflict fixture (covers those attr_name arms).
- Drop the unreachable `Nothing` arm from attr_name by typing the collected
  list to the four real tags and coercing the single-tag result.
@JonoPrest JonoPrest marked this pull request as ready for review June 2, 2026 13:17
@JonoPrest JonoPrest requested a review from cknitt June 2, 2026 13:17
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.

1 participant