From aa06fa819ef1c6774e73bd8ca1a5c1a78397ff45 Mon Sep 17 00:00:00 2001 From: Jeremy Yallop Date: Wed, 5 Aug 2020 10:49:13 +0100 Subject: [PATCH 1/2] Add a failing test for #show with -short-paths. --- .../tests/tool-toplevel/show_short_paths.ml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 testsuite/tests/tool-toplevel/show_short_paths.ml diff --git a/testsuite/tests/tool-toplevel/show_short_paths.ml b/testsuite/tests/tool-toplevel/show_short_paths.ml new file mode 100644 index 000000000..000e77523 --- /dev/null +++ b/testsuite/tests/tool-toplevel/show_short_paths.ml @@ -0,0 +1,19 @@ +(* TEST + flags = " -short-paths " + * expect +*) + +(* This is currently just a regression test for the bug + reported here: https://github.com/ocaml/ocaml/issues/9828 *) + +#show list;; +[%%expect {| +type 'a list = [] | (::) of 'a * 'a list +|}];; + +type 'a t;; +#show t;; +[%%expect {| +type 'a t +type 'a t +|}];; From 27f1012bc63e062adb63b4b9d6639588bfe1356a Mon Sep 17 00:00:00 2001 From: Jeremy Yallop Date: Wed, 5 Aug 2020 11:00:19 +0100 Subject: [PATCH 2/2] Revert to printing types as 'nonrec' to avoid a bug See: https://github.com/ocaml/ocaml/issues/9828 --- .../tool-toplevel/known-bugs/broken_rec_in_show.ml | 14 +++++++------- testsuite/tests/tool-toplevel/show.ml | 6 +++--- testsuite/tests/tool-toplevel/show_short_paths.ml | 4 ++-- toplevel/topdirs.ml | 2 +- 4 files changed, 13 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 255c4d10c..f4c3f497d 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,19 +10,19 @@ type t = T of t;; type t = T of t |}] #show t;; -(* this output is CORRECT, it does not use nonrec *) +(* this output is INCORRECT, it should not use nonrec *) [%%expect{| -type t = T of t +type nonrec t = T of t |}];; -type nonrec t = Foo of t;; +type nonrec s = Foo of t;; [%%expect{| -type nonrec t = Foo of t +type nonrec s = Foo of t |}];; -#show t;; -(* this output in INCORRECT, it should use nonrec *) +#show s;; +(* this output is CORRECT, it uses nonrec *) [%%expect{| -type t = Foo of t +type nonrec s = Foo of t |}];; diff --git a/testsuite/tests/tool-toplevel/show.ml b/testsuite/tests/tool-toplevel/show.ml index 9dd7dc664..6c000120e 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 'a option = None | Some of 'a +type nonrec 'a option = None | Some of 'a |}];; #show Open_binary;; @@ -59,7 +59,7 @@ type Stdlib.open_flag = #show open_flag;; [%%expect {| -type open_flag = +type nonrec open_flag = Open_rdonly | Open_wronly | Open_append @@ -90,7 +90,7 @@ type extensible += B of int #show extensible;; [%%expect {| -type extensible = .. +type nonrec 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 000e77523..c0c50de20 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 'a list = [] | (::) of 'a * 'a list +type nonrec 'a list = [] | (::) of 'a * 'a list |}];; type 'a t;; #show t;; [%%expect {| type 'a t -type 'a t +type nonrec 'a t |}];; diff --git a/toplevel/topdirs.ml b/toplevel/topdirs.ml index 20e6912ae..530a927f8 100644 --- a/toplevel/topdirs.ml +++ b/toplevel/topdirs.ml @@ -556,7 +556,7 @@ let () = reg_show_prim "show_type" (fun env loc id lid -> let _path, desc = Env.lookup_type ~loc lid env in - [ Sig_type (id, desc, Trec_first, Exported) ] + [ Sig_type (id, desc, Trec_not, Exported) ] ) "Print the signature of the corresponding type constructor."