Skip to content

Commit

Permalink
Merge pull request #1130 from ocaml/initial-escape
Browse files Browse the repository at this point in the history
Catch errors escaping from `Typemod.initial_env` for 4.08, 4.09 and 4.10
  • Loading branch information
trefis authored Apr 14, 2020
2 parents 23fd5c1 + aa55cfc commit a9fc339
Show file tree
Hide file tree
Showing 9 changed files with 63 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/ocaml/typing/408/typemod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ let initial_env ~loc ~safe_string ~initially_opened_module
let lid = {loc; txt = Longident.parse m } in
try
snd (type_open_ Override env lid.loc lid)
with Typetexp.Error _ as exn ->
with (Typetexp.Error _ | Magic_numbers.Cmi.Error _) as exn ->
Msupport.raise_error exn;
env
in
Expand Down
4 changes: 2 additions & 2 deletions src/ocaml/typing/409/persistent_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,8 @@ let check_pers_struct penv f1 f2 ~loc name =
| Not_found ->
let warn = Warnings.No_cmi_file(name, None) in
Location.prerr_warning loc warn
| Cmi_format.Error err ->
let msg = Format.asprintf "%a" Cmi_format.report_error err in
| Magic_numbers.Cmi.Error err ->
let msg = Format.asprintf "%a" Magic_numbers.Cmi.report_error err in
let warn = Warnings.No_cmi_file(name, Some msg) in
Location.prerr_warning loc warn
| Error err ->
Expand Down
2 changes: 1 addition & 1 deletion src/ocaml/typing/409/typemod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ let initial_env ~loc ~safe_string ~initially_opened_module
let lid = {loc; txt = Longident.parse m } in
try
snd (type_open_ Override env lid.loc lid)
with Typetexp.Error _ as exn ->
with (Typetexp.Error _ | Magic_numbers.Cmi.Error _) as exn ->
Msupport.raise_error exn;
env
in
Expand Down
4 changes: 2 additions & 2 deletions src/ocaml/typing/410/persistent_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ let check_pers_struct penv f1 f2 ~loc name =
| Not_found ->
let warn = Warnings.No_cmi_file(name, None) in
Location.prerr_warning loc warn
| Cmi_format.Error err ->
let msg = Format.asprintf "%a" Cmi_format.report_error err in
| Magic_numbers.Cmi.Error err ->
let msg = Format.asprintf "%a" Magic_numbers.Cmi.report_error err in
let warn = Warnings.No_cmi_file(name, Some msg) in
Location.prerr_warning loc warn
| Error err ->
Expand Down
2 changes: 1 addition & 1 deletion src/ocaml/typing/410/typemod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ let initial_env ~loc ~safe_string ~initially_opened_module
try
snd (type_open_ Override env lid.loc lid)
with
| (Typetexp.Error _ | Env.Error _) as exn ->
| (Typetexp.Error _ | Env.Error _ | Magic_numbers.Cmi.Error _) as exn ->
Msupport.raise_error exn;
env
| exn ->
Expand Down
Empty file.
46 changes: 46 additions & 0 deletions tests/test-dirs/no-escape/test.t
Original file line number Diff line number Diff line change
Expand Up @@ -307,3 +307,49 @@ And of course, it should never leak for other requests:
],
"notifications": []
}

When typing the Test module, Merlin will try to load the Foo dependency.
However foo.cmi is not a valid cmi file, we must make sure Merlin handle this
properly (this should also cover the "wrong magic number" case).

$ $MERLIN single errors -filename test_use.ml < test_use.ml | \
> tr '\r\n' ' ' | jq ".value |= (map(del(.start.line) | del(.end.line)))"
{
"class": "return",
"value": [
{
"start": {
"col": -1
},
"end": {
"col": -1
},
"type": "typer",
"sub": [],
"valid": true,
"message": "Corrupted compiled interface tests/test-dirs/no-escape/foo.cmi"
}
],
"notifications": []
}

$ $MERLIN single errors -filename test_open.ml -open Foo < test_open.ml | \
> tr '\r\n' ' ' | jq ".value |= (map(del(.start.line) | del(.end.line)))"
{
"class": "return",
"value": [
{
"start": {
"col": -1
},
"end": {
"col": -1
},
"type": "typer",
"sub": [],
"valid": true,
"message": "Corrupted compiled interface tests/test-dirs/no-escape/foo.cmi"
}
],
"notifications": []
}
9 changes: 9 additions & 0 deletions tests/test-dirs/no-escape/test_open.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
(* TODO or FIXME: If file is empty, Merlin just drops the errors
(errors are attached to typed top-level definitions,
if there are no definitions, errors cannot be attached!)
So here is a dummy definition.
*)


let () = print_string "Hello world"
1 change: 1 addition & 0 deletions tests/test-dirs/no-escape/test_use.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
open Foo

0 comments on commit a9fc339

Please sign in to comment.