Skip to content

Commit

Permalink
Fixed Merlin recovery causing incorrect error messages (#1709)
Browse files Browse the repository at this point in the history
from voodoos/issue1704-bad-error-messages
  • Loading branch information
voodoos authored Nov 27, 2023
2 parents 53eaad5 + 7cd451a commit 8380e47
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ merlin NEXT_VERSION
#1705)
- Fix Merlin locate not fallbacking on the correct file in case of ambiguity
(@goldfirere, #1699)
- Fix Merlin reporting errors provoked by the recovery itself (#1709, fixes
#1704)
+ editor modes
- vim: load merlin when Vim is compiled with +python3/dyn (e.g. MacVim)

Expand Down
4 changes: 3 additions & 1 deletion src/ocaml/typing/typedecl.ml
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,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 *)
Expand Down
6 changes: 4 additions & 2 deletions src/ocaml/typing/typetexp.ml
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,15 @@ type policy = Fixed | Extensible | Univars
let rec transl_type env policy styp =
Msupport.with_saved_types
~warning_attribute:styp.ptyp_attributes ?save_part:None
(fun () ->
(fun () ->
try
transl_type_aux env policy styp
with exn ->
let ty = new_global_var () in
Msupport.erroneous_type_register ty;
Msupport.raise_error exn;
{ ctyp_desc = Ttyp_any;
ctyp_type = new_global_var ();
ctyp_type = ty;
ctyp_env = env;
ctyp_loc = styp.ptyp_loc;
ctyp_attributes = [];
Expand Down
59 changes: 59 additions & 0 deletions tests/test-dirs/errors/issue1704-wrong-message.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
$ cat >test.ml <<'EOF'
> type foo = {
> bar: X.t;
> }
> type foo2 = X.t
> type foo3 = bar
> EOF

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 <test.ml
{
"class": "return",
"value": [
{
"start": {
"line": 2,
"col": 7
},
"end": {
"line": 2,
"col": 10
},
"type": "typer",
"sub": [],
"valid": true,
"message": "Unbound module X"
},
{
"start": {
"line": 4,
"col": 12
},
"end": {
"line": 4,
"col": 15
},
"type": "typer",
"sub": [],
"valid": true,
"message": "Unbound module X"
},
{
"start": {
"line": 5,
"col": 12
},
"end": {
"line": 5,
"col": 15
},
"type": "typer",
"sub": [],
"valid": true,
"message": "Unbound type constructor bar"
}
],
"notifications": []
}

0 comments on commit 8380e47

Please sign in to comment.