merlin icon indicating copy to clipboard operation
merlin copied to clipboard

Stack overflow when verbosity = 1

Open rgrinberg opened this issue 4 years ago • 4 comments

Consider this snippet:

type 'k t = 'k baz
and 'k baz =
  | Foo
  | Bar of 'k t

Now get the type enclosing of 'k t on the 4th line. You will see a stackoverflow:

  Raised by primitive operation at Ctype.expand_abbrev in file \"src/ocaml/typing/ctype.ml\" (inlined), line 1655, characters 2-57
  Called from Ctype.try_expand_once in file \"src/ocaml/typing/ctype.ml\", line 1675, characters 22-44
  Called from Ctype.try_expand_safe in file \"src/ocaml/typing/ctype.ml\", line 1681, characters 6-28
  Called from Ctype.try_expand_head in file \"src/ocaml/typing/ctype.ml\", line 1687, characters 12-27
  Called from Ctype.try_expand_head in file \"src/ocaml/typing/ctype.ml\", line 1688, characters 6-38
  Called from Ctype.try_expand_head in file \"src/ocaml/typing/ctype.ml\", line 1688, characters 6-38
  Called from Ctype.try_expand_head in file \"src/ocaml/typing/ctype.ml\", line 1688, characters 6-38

rgrinberg avatar Apr 30 '21 18:04 rgrinberg

PR #1336 reproduces

rgrinberg avatar Apr 30 '21 18:04 rgrinberg

This look like a duplicate, or at least a similar issue than https://github.com/ocaml/merlin/issues/1216. @trefis did you look into it since ?

voodoos avatar May 03 '21 09:05 voodoos

Btw, I also notice stackoverflows when hovering over recursive polymorphic variants in type definitions, which I think didn't happen before. I don't know whether it is better reported here or #1216.

Example:

Hovering over `A in the screenshot below raises a stackoverflow.

image

ulugbekna avatar May 03 '21 09:05 ulugbekna

did you look into it since?

No.

I'd say here the main issue is that we're trying to get the definition of a type constructor from inside its definition. The result (on both examples) is nonsense with a verbosity of 0, and a stack overflow with a greater verbosity. But these particular type declarations don't seem to be problematic as soon as the types are fully declared. So I suspect that detecting when we're looking at a type in the process of being declared and looking at his definition in an environment just after the declaration would make the problem disappear.

trefis avatar May 03 '21 14:05 trefis