ocaml-community / utop

Universal toplevel for OCaml
Other
833 stars 110 forks source link

Freezing on cyclic type abbreviations #467

Open mikeshulman opened 8 months ago

mikeshulman commented 8 months ago

In utop 2.13.1 for ocaml 5.1.0, entering

type t = t;;

causes the program to freeze and become unresponsive, instead of giving the correct error message "The type abbreviation t is cyclic" (which the ordinary toplevel does). This appears to be a regression since 2.12.1 for ocaml 5.0.0.

(It's possible this problem is not confined to utop, as I have also experienced a similar issue with Merlin, but only in a more complicated situation that I haven't managed to minimize yet.)

huwaireb commented 8 months ago

I've encountered the same issue only on OCaml 5.1.0 (didn't encounter on OCaml 5.0.0).

This also applies to

(* Cycle_in_def *)
type a = b
and b = a

as well, which is supposed to report a "The definition of %s contains a cycle", but instead results in a stack overflow shortly after freezing.

What I found odd however, is the following works just fine:

(* Recursive_abbrev *)
type ('a, 'b) t = ('b, 'a) t 

resulting in:

Error: The type abbreviation t is cyclic: ('a, 'b) t = ('b, 'a) t

but

(* Recursive_abbrev *)
type ('a, 'b) t = ('a, 'b) t

causes a stack overflow.

Screenshot 2023-11-15 at 3 27 24 PM

Seems to work fine in the ocaml repl as well

Screenshot 2023-11-15 at 3 32 15 PM
huwaireb commented 8 months ago

Occurs with dune as well, but seems to work on 5.2.0.