From 456473d87f09d1a4bc661ff7e328e2b806459ff2 Mon Sep 17 00:00:00 2001 From: Damien Doligez Date: Tue, 29 Nov 2011 15:54:41 +0000 Subject: [PATCH] better reporting of wrong version for .cmi files git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@11291 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02 --- typing/env.ml | 13 ++++++++++++- typing/env.mli | 1 + 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/typing/env.ml b/typing/env.ml index 3f119244f..0a868a701 100644 --- a/typing/env.ml +++ b/typing/env.ml @@ -25,6 +25,7 @@ open Btype type error = Not_an_interface of string + | Wrong_version_interface of string * string | Corrupted_interface of string | Illegal_renaming of string * string | Inconsistent_import of string * string * string @@ -177,7 +178,14 @@ let read_pers_struct modname filename = really_input ic buffer 0 (String.length cmi_magic_number); if buffer <> cmi_magic_number then begin close_in ic; - raise(Error(Not_an_interface filename)) + let pre_len = String.length cmi_magic_number - 3 in + if String.sub buffer 0 pre_len = String.sub cmi_magic_number 0 pre_len then + begin + let msg = if buffer < cmi_magic_number then "an older" else "a newer" in + raise (Error (Wrong_version_interface (filename, msg))) + end else begin + raise(Error(Not_an_interface filename)) + end end; let (name, sign) = input_value ic in let crcs = input_value ic in @@ -938,6 +946,9 @@ open Format let report_error ppf = function | Not_an_interface filename -> fprintf ppf "%s@ is not a compiled interface" filename + | Wrong_version_interface (filename, older_newer) -> fprintf ppf + "%s@ is not a compiled interface for this version of OCaml.@.\ + It seems to be for %s version of OCaml." filename older_newer | Corrupted_interface filename -> fprintf ppf "Corrupted compiled interface@ %s" filename | Illegal_renaming(modname, filename) -> fprintf ppf diff --git a/typing/env.mli b/typing/env.mli index 5816b0fdc..4e822de83 100644 --- a/typing/env.mli +++ b/typing/env.mli @@ -140,6 +140,7 @@ val summary: t -> summary type error = Not_an_interface of string + | Wrong_version_interface of string * string | Corrupted_interface of string | Illegal_renaming of string * string | Inconsistent_import of string * string * string