From 6140c07555d630e86b43024744a39316400d9882 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ulysse=20G=C3=A9rard?= Date: Tue, 21 Nov 2023 11:55:46 +0100 Subject: [PATCH 1/3] Add a test illustrating #1704 (cherry picked from commit 81a05bde46650032ffbe220152f187731b00bcdd) --- .../errors/issue1704-wrong-message.t | 104 ++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 tests/test-dirs/errors/issue1704-wrong-message.t diff --git a/tests/test-dirs/errors/issue1704-wrong-message.t b/tests/test-dirs/errors/issue1704-wrong-message.t new file mode 100644 index 000000000..d10783eff --- /dev/null +++ b/tests/test-dirs/errors/issue1704-wrong-message.t @@ -0,0 +1,104 @@ + $ cat >test.ml <<'EOF' + > type foo = { + > bar: X.t; + > } + > type foo2 = X.t + > type foo3 = bar + > EOF + +FIXME:Merlin should not report unbound variable errors in that case since it is +due to it's own type recovery. + $ $MERLIN single errors -filename test.ml Date: Tue, 21 Nov 2023 14:07:50 +0100 Subject: [PATCH 2/3] Fix issue #1704 by correctly registering erroneous types Co-authored-by: Thomas Refis (cherry picked from commit c05f3a35f9de2271aa44b2db601040e2154a87a8) --- src/ocaml/typing/typedecl.ml | 4 +- src/ocaml/typing/typetexp.ml | 7 +++ .../errors/issue1704-wrong-message.t | 47 +------------------ 3 files changed, 11 insertions(+), 47 deletions(-) diff --git a/src/ocaml/typing/typedecl.ml b/src/ocaml/typing/typedecl.ml index 50594434f..ebbac722b 100644 --- a/src/ocaml/typing/typedecl.ml +++ b/src/ocaml/typing/typedecl.ml @@ -1955,7 +1955,9 @@ let transl_type_decl env rec_flag sdecl_list = (fun sdecl tdecl -> let decl = tdecl.typ_type in match Ctype.closed_type_decl decl with - Some ty -> raise(Error(sdecl.ptype_loc, Unbound_type_var(ty,decl))) + Some ty -> + if not (Msupport.erroneous_type_check ty) then + raise(Error(sdecl.ptype_loc, Unbound_type_var(ty,decl))) | None -> ()) sdecl_list tdecls; (* Check that constraints are enforced *) diff --git a/src/ocaml/typing/typetexp.ml b/src/ocaml/typing/typetexp.ml index 132f60f05..2b3f24a47 100644 --- a/src/ocaml/typing/typetexp.ml +++ b/src/ocaml/typing/typetexp.ml @@ -644,9 +644,16 @@ let rec transl_type env ~policy ?(aliased=false) ~row_context mode styp = try transl_type_aux env ~policy ~aliased ~row_context mode styp with exn -> + let ty = new_global_var () in + Msupport.erroneous_type_register ty; Msupport.raise_error exn; +<<<<<<< HEAD { ctyp_desc = Ttyp_var (None, None); ctyp_type = new_global_var (Jkind.value ~why:(Unknown "merlin")); +======= + { ctyp_desc = Ttyp_any; + ctyp_type = ty; +>>>>>>> c05f3a35... Fix issue #1704 by correctly registering erroneous types ctyp_env = env; ctyp_loc = styp.ptyp_loc; ctyp_attributes = []; diff --git a/tests/test-dirs/errors/issue1704-wrong-message.t b/tests/test-dirs/errors/issue1704-wrong-message.t index d10783eff..b6e7faa11 100644 --- a/tests/test-dirs/errors/issue1704-wrong-message.t +++ b/tests/test-dirs/errors/issue1704-wrong-message.t @@ -6,27 +6,12 @@ > type foo3 = bar > EOF -FIXME:Merlin should not report unbound variable errors in that case since it is +Merlin should not report unbound variable errors in that case since it is due to it's own type recovery. $ $MERLIN single errors -filename test.ml Date: Mon, 29 Apr 2024 11:13:07 -0400 Subject: [PATCH 3/3] Fix merge conflicts from backport --- src/ocaml/typing/typetexp.ml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/ocaml/typing/typetexp.ml b/src/ocaml/typing/typetexp.ml index 2b3f24a47..3bf96633b 100644 --- a/src/ocaml/typing/typetexp.ml +++ b/src/ocaml/typing/typetexp.ml @@ -644,16 +644,11 @@ let rec transl_type env ~policy ?(aliased=false) ~row_context mode styp = try transl_type_aux env ~policy ~aliased ~row_context mode styp with exn -> - let ty = new_global_var () in + let ty = new_global_var (Jkind.value ~why:(Unknown "merlin")) in Msupport.erroneous_type_register ty; Msupport.raise_error exn; -<<<<<<< HEAD { ctyp_desc = Ttyp_var (None, None); - ctyp_type = new_global_var (Jkind.value ~why:(Unknown "merlin")); -======= - { ctyp_desc = Ttyp_any; ctyp_type = ty; ->>>>>>> c05f3a35... Fix issue #1704 by correctly registering erroneous types ctyp_env = env; ctyp_loc = styp.ptyp_loc; ctyp_attributes = [];