Commit 62ecbbc
authored
Improve unclear error and warning messages (rescript-lang#8460)
* Improve non-function application error wording
Saying "The function has type" right after "it's not a function" was
contradictory. Use "It has type" instead.
* Improve @return(*_to_opt) error message
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.
* Improve @int variant @as payload error message
"expect int literal" was terse and contextless. Name the attribute and
show the expected form.
* Improve conflicting-attributes error message
"conflicting attributes" did not say which attributes conflict. List the
mutually-exclusive set (@string, @int, @ignore, @unwrap).
* Render @ correctly in FFI attribute error messages
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.
* Improve @this simple-pattern error message
Fix the "%@this" rendering and the broken grammar ("expect its pattern
variable to be simple form"). State what is required and why.
* Tidy the "expected a string literal" error message
Capitalize and use a full sentence instead of "expect string literal "
(trailing space). Kept generic since it is shared by @as payloads and
@@directive.
* Tidy the @as int/string/json literal error message
Replace "expect int, string literal or json literal {json|text here|json}"
with a plain sentence.
* Tighten @this and @return wording for accuracy
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.
* Fix subject-verb agreement in type-params-not-supported error
* Fix list grammar in @as variant annotation error
* Use ReScript-style quoting for `let rec` in letrec errors
Replace the OCaml-style `let rec' quoting with `let rec`.
* Drop OCaml-manual references from warning messages
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.
* Improve duplicate @as annotation error wording
* Improve duplicate @deriving attribute error wording
* Improve unsupported @return directive error message
List the supported directives instead of the terse "Not supported return
directive".
* Make duplicate @as message context-neutral
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".
* Report the real attribute name in misplaced @inline warning
The misplaced-@inline warning hardcoded "inline1"/"inline2" as the
attribute name, leaking an internal distinction; the user wrote @inline. Use
the real attribute name.
* Use @-prefixed attribute names in attribute warnings
Warnings 47/53/54 referred to attributes as "inline" / 'inline'; ReScript
messages elsewhere use the @-prefixed form (@as, @deriving, ...). Use @inline
etc. for consistency.
* Name the conflicting attributes in the conflict error
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.
* Use 'switch' instead of OCaml ''match' expression' in no-value-clauses error
* Say 'pattern' instead of OCaml 'matching' in multiply-bound-variable error
* Clarify the fragile-pattern-in-toplevel error wording
* State the rule in the invalid type-variable-name error
"is not allowed in programs" was vague; type variable names cannot start
with an underscore.
* Fix pluralization and phrasing in type-arity-mismatch error
"expects 1 argument(s), but is here applied to 2 argument(s)" -> proper
singular/plural and "is given".
* Clarify packed-module / GADT-pattern / existential error messages
- 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
* Backtick the type-constructor name in type-arity-mismatch error
Quote the name like the other polished messages (and the same message's
zero-argument branch already does).
* Add changelog entry for error/warning message improvements
* Capitalize two lowercase error messages for consistency
Errors are sentence-case; "unsupported predicates" and the consecutive-
statements syntax error started lowercase.
* Cover new error-message branches flagged by codecov
- 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.1 parent 77a6290 commit 62ecbbc
66 files changed
Lines changed: 175 additions & 120 deletions
File tree
- compiler
- ext
- frontend
- ml
- syntax/src
- tests
- analysis_tests/tests/not_compiled/expected
- build_tests
- super_errors_multi/expected
- super_errors
- expected
- fixtures
- syntax_tests/data/parsing
- errors
- expressions/expected
- pattern/expected
- scanner/expected
- structure/expected
- grammar/ffi/expected
- infiniteLoops/expected
- other/expected
Some content is hidden
Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
46 | 46 | | |
47 | 47 | | |
48 | 48 | | |
| 49 | + | |
49 | 50 | | |
50 | 51 | | |
51 | 52 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
373 | 373 | | |
374 | 374 | | |
375 | 375 | | |
376 | | - | |
| 376 | + | |
377 | 377 | | |
378 | 378 | | |
379 | 379 | | |
| |||
383 | 383 | | |
384 | 384 | | |
385 | 385 | | |
386 | | - | |
| 386 | + | |
387 | 387 | | |
388 | 388 | | |
389 | 389 | | |
390 | 390 | | |
391 | | - | |
| 391 | + | |
392 | 392 | | |
393 | | - | |
| 393 | + | |
394 | 394 | | |
395 | 395 | | |
396 | 396 | | |
397 | 397 | | |
398 | 398 | | |
399 | 399 | | |
400 | 400 | | |
401 | | - | |
| 401 | + | |
402 | 402 | | |
403 | 403 | | |
404 | 404 | | |
405 | | - | |
| 405 | + | |
406 | 406 | | |
407 | 407 | | |
408 | 408 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
161 | 161 | | |
162 | 162 | | |
163 | 163 | | |
164 | | - | |
165 | | - | |
166 | | - | |
167 | | - | |
168 | | - | |
169 | | - | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
170 | 169 | | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
177 | | - | |
178 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
179 | 189 | | |
180 | 190 | | |
181 | 191 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
623 | 623 | | |
624 | 624 | | |
625 | 625 | | |
626 | | - | |
| 626 | + | |
627 | 627 | | |
628 | 628 | | |
629 | 629 | | |
| |||
649 | 649 | | |
650 | 650 | | |
651 | 651 | | |
652 | | - | |
| 652 | + | |
653 | 653 | | |
654 | 654 | | |
655 | 655 | | |
| |||
750 | 750 | | |
751 | 751 | | |
752 | 752 | | |
753 | | - | |
| 753 | + | |
754 | 754 | | |
755 | 755 | | |
756 | 756 | | |
| |||
777 | 777 | | |
778 | 778 | | |
779 | 779 | | |
780 | | - | |
| 780 | + | |
781 | 781 | | |
782 | 782 | | |
783 | 783 | | |
| |||
856 | 856 | | |
857 | 857 | | |
858 | 858 | | |
859 | | - | |
| 859 | + | |
860 | 860 | | |
861 | 861 | | |
862 | 862 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
61 | | - | |
62 | | - | |
63 | | - | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
64 | 66 | | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
70 | 78 | | |
71 | | - | |
| 79 | + | |
72 | 80 | | |
73 | 81 | | |
74 | | - | |
75 | | - | |
| 82 | + | |
| 83 | + | |
76 | 84 | | |
77 | | - | |
| 85 | + | |
78 | 86 | | |
79 | 87 | | |
80 | 88 | | |
81 | 89 | | |
82 | | - | |
| 90 | + | |
83 | 91 | | |
84 | 92 | | |
85 | 93 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | | - | |
| 30 | + | |
31 | 31 | | |
32 | 32 | | |
33 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
73 | 73 | | |
74 | 74 | | |
75 | 75 | | |
76 | | - | |
77 | | - | |
78 | | - | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
472 | 472 | | |
473 | 473 | | |
474 | 474 | | |
475 | | - | |
| 475 | + | |
476 | 476 | | |
477 | 477 | | |
478 | 478 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
79 | 79 | | |
80 | 80 | | |
81 | 81 | | |
82 | | - | |
| 82 | + | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
486 | 486 | | |
487 | 487 | | |
488 | 488 | | |
489 | | - | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
490 | 492 | | |
491 | 493 | | |
492 | 494 | | |
| |||
0 commit comments