ocaml / merlin

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

GADTs: Incorrect types inferred in recursive function while modifying code #1829

Open 2BitSalute opened 2 months ago

2BitSalute commented 2 months ago

Sorry this repro is a bit long, but I couldn't reduce it any further. It's something about the presence of all the elements in this example that triggers the incorrect errors, and also the order seems to matter.

The error persists in the file until I restart the language server.

Steps

  1. Start with repro_initial.ml
    • Dune: (libraries core core_unix core_unix.sys_unix)
  2. Change line 4 from | Step : ('a -> 'b)... to | Step : string * ('a -> 'b)...
  3. Fix up the rest of the code: ( @> ), exec_with_profile, then sum_file_sizes

Expected

No errros

Actual

At line 28 (the recursive base case of exec_with_profile), 2 errors appear.

Empty

Empty should be of type ('a, 'a) pipeline.

However, it is identified as (string list, string list) pipeline, and it is underlined with this error:

This pattern matches values of type (string list, string list) pipeline but a pattern was expected which matches values of type (input, output) pipeline The type constructor output would escape its scope (ocamllsp)

input

input should be of the locally abstract type input, but it seems to be string list, if I'm reading the error correctly.

This is the error:

This expression has type input = string list but an expression was expected of type output This instance of string list is ambiguous: it would escape the scope of its equation (ocamllsp)

I trimmed the recording just to where the error first appears, which is when I still have a few things to fix up, but even after the code compiles, the 2 errors persist.

https://github.com/user-attachments/assets/65172c7d-a2e6-4736-ae4e-cae9bf6237e3