diff options
author | Florian Angeletti <florian.angeletti@inria.fr> | 2021-05-18 14:40:06 +0200 |
---|---|---|
committer | octachron <octa@polychoron.fr> | 2021-05-19 13:10:17 +0200 |
commit | 22e3e03f82c1556d30f19e7608fcd8c6f348bcec (patch) | |
tree | f17818bad33592e9471af1dc618e5e4628d15d8f /testsuite | |
parent | 5fbd6e15c8ccffeb533389e4695223fbc9370b4b (diff) | |
download | ocaml-22e3e03f82c1556d30f19e7608fcd8c6f348bcec.tar.gz |
toplevel: detect recursive definitions in #show
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/tests/tool-toplevel/known-bugs/broken_rec_in_show.ml | 49 | ||||
-rw-r--r-- | testsuite/tests/tool-toplevel/show.ml | 6 | ||||
-rw-r--r-- | testsuite/tests/tool-toplevel/show_short_paths.ml | 4 |
3 files changed, 46 insertions, 13 deletions
diff --git a/testsuite/tests/tool-toplevel/known-bugs/broken_rec_in_show.ml b/testsuite/tests/tool-toplevel/known-bugs/broken_rec_in_show.ml index d4160db712..688ac53844 100644 --- a/testsuite/tests/tool-toplevel/known-bugs/broken_rec_in_show.ml +++ b/testsuite/tests/tool-toplevel/known-bugs/broken_rec_in_show.ml @@ -10,9 +10,9 @@ type t = T of t;; type t = T of t |}] #show t;; -(* this output is INCORRECT, it should not use nonrec *) +(* this output is CORRECT, it should not use nonrec *) [%%expect{| -type nonrec t = T of t +type t = T of t |}];; type nonrec s = Foo of t;; @@ -20,9 +20,9 @@ type nonrec s = Foo of t;; type nonrec s = Foo of t |}];; #show s;; -(* this output is CORRECT, it uses nonrec *) +(* this output is CORRECT, it elides the unnecessary nonrec keyword *) [%%expect{| -type nonrec s = Foo of t +type s = Foo of t |}];; @@ -32,8 +32,6 @@ module M : sig type t val x : t end = struct type t = int let x = 0 end;; module M : sig type t val x : t end |}];; (* this output is CORRECT, it does not use 'rec' *) -[%%expect{| -|}];; module rec M : sig type t val x : M.t end = struct type t = int let x = 0 end;; (* this output is CORRECT . *) @@ -41,7 +39,42 @@ module rec M : sig type t val x : M.t end = struct type t = int let x = 0 end;; module rec M : sig type t val x : M.t end |}];; #show_module M;; -(* this output is INCORRECT, it should use 'rec' *) +(* this output is CORRECT *) +[%%expect{| +module rec M : sig type t val x : M.t end +|}];; + + +(* Indirect recursion *) + +type t +type f = [ `A of t ] +type t = X of u | Y of [ f | `B ] and u = Y of t;; + +[%%expect{| +type t +type f = [ `A of t ] +type t = X of u | Y of [ `A of t/1 | `B ] +and u = Y of t/2 +|}];; + +#show t;; +(* this output is PARTIAL: t is mutually recursive with u *) +[%%expect{| +type nonrec t = X of u | Y of [ `A of t/2 | `B ] +|}];; + + +module rec M: sig type t = X of N.t end = M +and N: sig type t = X of M.t end = N + +[%%expect{| +module rec M : sig type t = X of N.t end +and N : sig type t = X of M.t end +|}];; + +(* this output is PARTIAL: M is mutually recursive with N *) +#show M;; [%%expect{| -module M : sig type t val x : M.t end +module M : sig type t = X of N.t end |}];; diff --git a/testsuite/tests/tool-toplevel/show.ml b/testsuite/tests/tool-toplevel/show.ml index 6c000120ec..9dd7dc664b 100644 --- a/testsuite/tests/tool-toplevel/show.ml +++ b/testsuite/tests/tool-toplevel/show.ml @@ -40,7 +40,7 @@ type 'a option = None | Some of 'a #show option;; [%%expect {| -type nonrec 'a option = None | Some of 'a +type 'a option = None | Some of 'a |}];; #show Open_binary;; @@ -59,7 +59,7 @@ type Stdlib.open_flag = #show open_flag;; [%%expect {| -type nonrec open_flag = +type open_flag = Open_rdonly | Open_wronly | Open_append @@ -90,7 +90,7 @@ type extensible += B of int #show extensible;; [%%expect {| -type nonrec extensible = .. +type extensible = .. |}];; type 'a t = ..;; diff --git a/testsuite/tests/tool-toplevel/show_short_paths.ml b/testsuite/tests/tool-toplevel/show_short_paths.ml index c0c50de20c..000e775234 100644 --- a/testsuite/tests/tool-toplevel/show_short_paths.ml +++ b/testsuite/tests/tool-toplevel/show_short_paths.ml @@ -8,12 +8,12 @@ #show list;; [%%expect {| -type nonrec 'a list = [] | (::) of 'a * 'a list +type 'a list = [] | (::) of 'a * 'a list |}];; type 'a t;; #show t;; [%%expect {| type 'a t -type nonrec 'a t +type 'a t |}];; |