ocaml / merlin

Context sensitive completion for OCaml in Vim and Emacs
https://ocaml.github.io/merlin/
MIT License
1.58k stars 233 forks source link

merlin is missing unused (type|open|value|constructor|field) warnings #1593

Open copy opened 1 year ago

copy commented 1 year ago

e.g.:

open Printf

module type X = sig end

let x =
  let y = 42 in
  ()

let _f x = ()

type x = {
  foo: int }
type y =
  | Foo

let () = for i = 0 to 0 do () done

with an empty test.mli and the following dune:

(executable (name test))

There are a bunch of different unused warnings (I didn't manage to get an unused module warning out of the compiler):

% dune clean && dune build test.exe
File "test.ml", line 1, characters 0-11:
1 | open Printf
    ^^^^^^^^^^^
Error (warning 33 [unused-open]): unused open Stdlib.Printf.
File "test.ml", line 5, characters 4-5:
5 | let x =
        ^
Error (warning 32 [unused-value-declaration]): unused value x.
File "test.ml", line 6, characters 6-7:
6 |   let y = 42 in
          ^
Error (warning 26 [unused-var]): unused variable y.
File "test.ml", line 9, characters 7-8:
9 | let _f x = ()
           ^
Error (warning 27 [unused-var-strict]): unused variable x.
File "test.ml", lines 11-12, characters 0-12:
11 | type x = {
12 |   foo: int }
Error (warning 34 [unused-type-declaration]): unused type x.
File "test.ml", line 12, characters 2-10:
12 |   foo: int }
       ^^^^^^^^
Error (warning 69 [unused-field]): unused record field foo.
File "test.ml", lines 13-14, characters 0-7:
13 | type y =
14 |   | Foo
Error (warning 34 [unused-type-declaration]): unused type y.
File "test.ml", line 14, characters 2-7:
14 |   | Foo
       ^^^^^
Error (warning 37 [unused-constructor]): unused constructor Foo.
File "test.ml", line 16, characters 9-34:
16 | let () = for i = 0 to 0 do () done
              ^^^^^^^^^^^^^^^^^^^^^^^^^
Error (warning 35 [unused-for-index]): unused for-loop index i.

But merlin only reports warning 26:

% ocamlmerlin single errors < test.ml |jq
{
  "class": "return",
  "value": [
    {
      "start": {
        "line": 6,
        "col": 6
      },
      "end": {
        "line": 6,
        "col": 7
      },
      "type": "warning",
      "sub": [],
      "valid": true,
      "message": "Warning 26: unused variable y."
    }
  ],
  "notifications": [],
  "timing": {
    "clock": 2,
    "cpu": 2,
    "query": 0,
    "pp": 0,
    "reader": 0,
    "ppx": 0,
    "typer": 2,
    "error": 0
  }
}

This is with merlin 4.8-500.

voodoos commented 1 year ago

Yes, these warnings have always been disabled in Merlin: https://github.com/ocaml/merlin/commit/1f1fee1ed6e08cede167d00130e42a9646dff7f5

https://github.com/ocaml/merlin/blob/1f1fee1ed6e08cede167d00130e42a9646dff7f5/src/ocaml/typer_403/utils/warnings.ml#L207-L208

I always assumed that the reason was to not bother the user while writing code since most values start their life unused. But the comment in the code actually says Some warnings are not properly implemented in merlin, just disable which I find a bit surprising.

@let-def could you give us some insight about this ?

Linked-issue: #485