diff --git a/src/format/opamFile.ml b/src/format/opamFile.ml index 45c63bee925..3320f3deb8c 100644 --- a/src/format/opamFile.ml +++ b/src/format/opamFile.ml @@ -1016,15 +1016,24 @@ module SyntaxFile(X: SyntaxFileArg) : IO_FILE with type t := X.t = struct module IO = struct let to_opamfile filename t = Pp.print X.pp (filename, t) + let catch_future_syntax_error = function + | {file_contents = [{pelem = Variable({pelem = "opam-version"; _}, {pelem = String ver; _}); _ }; + {pelem = Section {section_kind = {pelem = "#"; _}; _}; pos}]; _} + when OpamVersion.(compare (nopatch (of_string ver)) (nopatch X.format_version)) <= 0 -> + raise (OpamPp.Bad_format (Some pos, "Parse error")) + | opamfile -> opamfile + let of_channel filename (ic:in_channel) = - Pp.parse X.pp ~pos:(pos_file filename) (Syntax.of_channel filename ic) + let opamfile = Syntax.of_channel filename ic |> catch_future_syntax_error in + Pp.parse X.pp ~pos:(pos_file filename) opamfile |> snd let to_channel filename oc t = Syntax.to_channel filename oc (to_opamfile filename t) let of_string (filename:filename) str = - Pp.parse X.pp ~pos:(pos_file filename) (Syntax.of_string filename str) + let opamfile = Syntax.of_string filename str |> catch_future_syntax_error in + Pp.parse X.pp ~pos:(pos_file filename) opamfile |> snd let to_string filename t =