diff --git a/master_changes.md b/master_changes.md index ed5e2cce5f0..d2515019bb7 100644 --- a/master_changes.md +++ b/master_changes.md @@ -92,6 +92,7 @@ users) ## Opamfile * Make all writes atomic [#5489 @kit-ty-kate] + * Ensure future syntax errors are only reported when the syntax version is greater than the client, not the format library [#6199 @dra27 - fix #6188] ## External dependencies * Always pass --no-version-check and --no-write-registry to Cygwin setup [#6046 @dra27] diff --git a/src/format/opamFile.ml b/src/format/opamFile.ml index 8ce547f4c72..71bf3857562 100644 --- a/src/format/opamFile.ml +++ b/src/format/opamFile.ml @@ -874,9 +874,14 @@ module Syntax = struct let filename = OpamFilename.to_string filename in lexbuf.Lexing.lex_curr_p <- { lexbuf.Lexing.lex_curr_p with Lexing.pos_fname = filename }; - try OpamParser.main OpamLexer.token lexbuf filename with - | OpamLexer.Error msg -> error msg - | Parsing.Parse_error -> error "Parse error" + match OpamParser.main OpamLexer.token lexbuf filename with + | {file_contents = [{pelem = Variable({pelem = "opam-version"; _}, {pelem = String ver; _}); _ }; + {pelem = Section {section_kind = {pelem = "#"; _}; _}; _}]; _} + when OpamVersion.(compare (nopatch (of_string ver)) (nopatch OpamVersion.current)) <= 0 -> + error "Parse error" + | opamfile -> opamfile + | exception OpamLexer.Error msg -> error msg + | exception Parsing.Parse_error -> error "Parse error" let pp_channel filename ic oc = diff --git a/tests/reftests/lint.test b/tests/reftests/lint.test index f9ad2ba2152..8f30f3c8070 100644 --- a/tests/reftests/lint.test +++ b/tests/reftests/lint.test @@ -1262,11 +1262,11 @@ ${BASEDIR}/future/pin-at-two-one.opam: Errors. # Return code 1 # ### opam lint future/pin-at-two-two.opam ${BASEDIR}/future/pin-at-two-two.opam: Errors. - error 2: File format error: unsupported or missing file format version; should be 2.0 or older + error 2: File format error at line 11, column 0: Parse error # Return code 1 # ### opam lint future/pin-at-two-three.opam ${BASEDIR}/future/pin-at-two-three.opam: Errors. - error 2: File format error: unsupported or missing file format version; should be 2.0 or older + error 2: File format error at line 11, column 0: Parse error # Return code 1 # ### opam lint future/pin-at-future.opam ${BASEDIR}/future/pin-at-future.opam: Errors.