diff --git a/CHANGELOG.md b/CHANGELOG.md index 74a31ce9e1..816dd20a59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ #### :nail_care: Polish +- Add some context to error message for unused variables. https://github.com/rescript-lang/rescript-compiler/pull/7050 - Improve error message when passing `children` prop to a component that doesn't accept it. https://github.com/rescript-lang/rescript-compiler/pull/7044 - Improve error messages for pattern matching on option vs non-option, and vice versa. https://github.com/rescript-lang/rescript-compiler/pull/7035 - Improve bigint literal comparison. https://github.com/rescript-lang/rescript-compiler/pull/7029 diff --git a/jscomp/build_tests/super_errors/expected/unused_variable.res.expected b/jscomp/build_tests/super_errors/expected/unused_variable.res.expected new file mode 100644 index 0000000000..dfaad847e4 --- /dev/null +++ b/jscomp/build_tests/super_errors/expected/unused_variable.res.expected @@ -0,0 +1,15 @@ + + Warning number 26 + /.../fixtures/unused_variable.res:2:7 + + 1 │ let x = { + 2 │ let f = 12 + 3 │ 13 + 4 │ } + + unused variable f. + +Fix this by: +- Deleting the variable if it's not used anymiore. +- Prepending the variable name with `_` (like `_f`) to ignore that the variable is unused. +- Using the variable somewhere. \ No newline at end of file diff --git a/jscomp/build_tests/super_errors/fixtures/unused_variable.res b/jscomp/build_tests/super_errors/fixtures/unused_variable.res new file mode 100644 index 0000000000..42d2252b3d --- /dev/null +++ b/jscomp/build_tests/super_errors/fixtures/unused_variable.res @@ -0,0 +1,4 @@ +let x = { + let f = 12 + 13 +} diff --git a/jscomp/ext/warnings.ml b/jscomp/ext/warnings.ml index 06233bf643..0b16549056 100644 --- a/jscomp/ext/warnings.ml +++ b/jscomp/ext/warnings.ml @@ -378,7 +378,8 @@ let message = function | All_clauses_guarded -> "this pattern-matching is not exhaustive.\n\ All clauses in this pattern-matching are guarded." - | Unused_var v | Unused_var_strict v -> "unused variable " ^ v ^ "." + | Unused_var v | Unused_var_strict v -> + Format.sprintf "unused variable %s.\n\nFix this by:\n- Deleting the variable if it's not used anymiore.\n- Prepending the variable name with `_` (like `_%s`) to ignore that the variable is unused.\n- Using the variable somewhere." v v | Wildcard_arg_to_constant_constr -> "wildcard pattern given as argument to a constant constructor" | Eol_in_string ->