Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

module with type constraint crashes merlin #1322

Closed
EduardoRFS opened this issue Apr 18, 2021 · 7 comments · Fixed by #1334 or ocaml/opam-repository#20090
Closed

module with type constraint crashes merlin #1322

EduardoRFS opened this issue Apr 18, 2021 · 7 comments · Fixed by #1334 or ocaml/opam-repository#20090

Comments

@EduardoRFS
Copy link

I'm actually using ocaml-lsp but this seems to be caused by the code on the editor, so probably it's merlin fault. The following code crashes the ocaml-lsp, by removing the constraint part it stops crashing, but of course it doesn't do the same thing.

module type Monad = sig
  type 'a t
end
module type Monad_option = Monad with type 'a t = 'a option constraint 'a = int
@voodoos
Copy link
Collaborator

voodoos commented Apr 19, 2021

I copy-pasted your example on my editor using OCaml-LSP, tried to hover on a few parts of it, but could not produce a crash. Can you give more precise instructions on how you trigger the crash ?

@EduardoRFS
Copy link
Author

EduardoRFS commented Apr 19, 2021

You need to build first, if it doesn't have a config it works. Build it using dune, then hover it.

Repro repo below

Editor: VSCode
OS: Arch Linux
Package Manager: esy or opam

https://github.com/EduardoRFS/repro-crashes-lsp

@voodoos
Copy link
Collaborator

voodoos commented Apr 19, 2021

Thank you I was able to reproduce the crash.
Calling Merlin directly does not causes a crash but a failure:

❯ ocamlmerlin single errors -position 6:18 -filename hover_this.ml < hover_this.ml | jq
{
  "class": "failure",
  "value": "Graph.add: type already defined",
  "notifications": [],
  "timing": {
   ...
  }
}

This comes from ocaml/typing/short_paths_graph.ml.

I guess it is bad that Merlin reports this failure instead of the expected error which is:

File "hover_this.ml", lines 5-7, characters 2-23:
5 | ..Monad
6 |     with type 'a t = 'a option
7 |     constraint 'a = int
Error: In this `with' constraint, the new definition of t
       does not match its original definition in the constrained signature:
       Type declarations do not match:
         type 'a t = 'a option constraint 'a = int
       is not included in
         type 'a t
       Their constraints differ.
       File "hover_this.ml", line 2, characters 2-11: Expected declaration
       File "hover_this.ml", lines 6-7, characters 9-23: Actual declaration

@trefis do you have an idea of what is happening here ?

@voodoos
Copy link
Collaborator

voodoos commented Apr 19, 2021

Surprisingly it only happens after building:

$ dune clean
$ ocamlmerlin single errors -filename hover_this.ml < hover_this.ml| jq
{
  "class": "return",
  "value": [
    {
      "type": "config",
      "sub": [],
      "valid": true,
      "message": "No config found for file \"hover_this.ml\" in \".\". Try calling `dune build`."
    },
    {
      "start": {
        "line": 5,
        "col": 2
      },
      "end": {
        "line": 7,
        "col": 23
      },
      "type": "typer",
      "sub": [],
      "valid": true,
      "message": "In this `with' constraint, the new definition of t\ndoes not match its original definition in the constrained signature:\nType declarations do not match:\n  type 'a t = 'a option constraint 'a = int\nis not included in\n  type 'a t\nTheir constraints differ.\nFile \"hover_this.ml\", line 2, characters 2-11: Expected declaration\nFile \"hover_this.ml\", line 6, characters 9-54: Actual declaration"
    }
  ],
  "notifications": [],
  "timing": {
    "clock": 19,
    "cpu": 4,
    "query": 1,
    "pp": 0,
    "reader": 1,
    "ppx": 0,
    "typer": 2,
    "error": 0
  }
}


$ dune build
File "hover_this.ml", lines 5-7, characters 2-23:
5 | ..Monad
6 |     with type 'a t = 'a option
7 |     constraint 'a = int
Error: In this `with' constraint, the new definition of t
       does not match its original definition in the constrained signature:
       Type declarations do not match:
         type 'a t = 'a option constraint 'a = int
       is not included in
         type 'a t
       Their constraints differ.
       File "hover_this.ml", line 2, characters 2-11: Expected declaration
       File "hover_this.ml", lines 6-7, characters 9-23: Actual declaration
$ ocamlmerlin single errors -filename hover_this.ml < hover_this.ml| jq
{
  "class": "failure",
  "value": "Graph.add: type already defined",
  "notifications": [],
  "timing": {
    "clock": 25,
    "cpu": 7,
    "query": 3,
    "pp": 0,
    "reader": 1,
    "ppx": 0,
    "typer": 2,
    "error": 0
  }
}

@trefis
Copy link
Contributor

trefis commented Apr 19, 2021

-short-paths falls into @lpw25's area of expertise, so I'll defer to him.

@rgrinberg
Copy link
Member

Surprisingly it only happens after building:

Probably because short paths is only turned on after dune prints the merlin config that enables short-paths.

I fixed a similar issue recently: ocaml/ocaml-lsp#429 the pretty printing code was causing a similar exceptions.

@lpw25
Copy link
Contributor

lpw25 commented Apr 29, 2021

Cherry-picking the change in ocaml/ocaml#10382 fixes this issue.

voodoos added a commit to voodoos/opam-repository that referenced this issue Nov 23, 2021
CHANGES:

Mon Jul 26 11:12:21 PM CET 2021

  + merlin binary
    - Mbrowse.select_leaf: correctly ignore merlin.hide (ocaml/merlin#1376)
    - enable `occurences` to work when looking for locally abstract types
      (ocaml/merlin#1382)
    - handle `-alert` compiler flag (ocaml/merlin#1401)
    - avoid a race condition when the process started to read a configuration
      file crashes/is not found (ocaml/merlin#1378, @antalsz)
    - log the backtrace even when the exception is a Failure (ocaml/merlin#1377, @antalsz)
    - ignore `-error-style` compiler flag (ocaml/merlin#1402, @nojb)
    - fix handling of record field expressions (ocaml/merlin#1375)
    - allow -pp to return an AST (ocaml/merlin#1394)
    - fix merlin crashing due to short-paths (ocaml/merlin#1334, fixes ocaml/merlin#1322)
  + editor modes
    - update quick setup instructions for emacs (ocaml/merlin#1380, @ScriptDevil)
  + test suite
    - improve record field destruction testing (ocaml/merlin#1375)
voodoos added a commit to voodoos/opam-repository that referenced this issue Nov 23, 2021
CHANGES:

Mon Jul 26 11:12:21 PM CET 2021

  + ocaml support
    - add support for 4.13
    - stopped actively supporting version older than 4.12
  + merlin binary
    - Mbrowse.select_leaf: correctly ignore merlin.hide (ocaml/merlin#1376)
    - enable `occurences` to work when looking for locally abstract types
      (ocaml/merlin#1382)
    - handle `-alert` compiler flag (ocaml/merlin#1401)
    - avoid a race condition when the process started to read a configuration
      file crashes/is not found (ocaml/merlin#1378, @antalsz)
    - log the backtrace even when the exception is a Failure (ocaml/merlin#1377, @antalsz)
    - ignore `-error-style` compiler flag (ocaml/merlin#1402, @nojb)
    - fix handling of record field expressions (ocaml/merlin#1375)
    - allow -pp to return an AST (ocaml/merlin#1394)
    - fix merlin crashing due to short-paths (ocaml/merlin#1334, fixes ocaml/merlin#1322)
  + editor modes
    - update quick setup instructions for emacs (ocaml/merlin#1380, @ScriptDevil)
  + test suite
    - improve record field destruction testing (ocaml/merlin#1375)
voodoos added a commit to voodoos/opam-repository that referenced this issue Nov 23, 2021
CHANGES:

Mon Jul 26 11:12:21 PM CET 2021

  + merlin binary
    - Mbrowse.select_leaf: correctly ignore merlin.hide (ocaml/merlin#1376)
    - enable `occurences` to work when looking for locally abstract types
      (ocaml/merlin#1382)
    - handle `-alert` compiler flag (ocaml/merlin#1401)
    - avoid a race condition when the process started to read a configuration
      file crashes/is not found (ocaml/merlin#1378, @antalsz)
    - log the backtrace even when the exception is a Failure (ocaml/merlin#1377, @antalsz)
    - ignore `-error-style` compiler flag (ocaml/merlin#1402, @nojb)
    - fix handling of record field expressions (ocaml/merlin#1375)
    - allow -pp to return an AST (ocaml/merlin#1394)
    - fix merlin crashing due to short-paths (ocaml/merlin#1334, fixes ocaml/merlin#1322)
  + editor modes
    - update quick setup instructions for emacs (ocaml/merlin#1380, @ScriptDevil)
  + test suite
    - improve record field destruction testing (ocaml/merlin#1375)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants