Skip to content

Commit a216344

Browse files
dra27rjbou
andcommitted
Detect future syntax errors in the Syntax helper
Repository parsing and linting use a slightly different parsing route which wasn't checking for future syntax errors. Co-authored-by: Raja Boujbel <raja.boujbel@ocamlpro.com>
1 parent 2a07dec commit a216344

File tree

4 files changed

+16
-7
lines changed

4 files changed

+16
-7
lines changed

master_changes.md

+1
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ users)
9494
## Opamfile
9595
* Make all writes atomic [#5489 @kit-ty-kate]
9696
* Propagate future opamfile parse errors correctly [#6199 @dra27]
97+
* Ensure future syntax errors are only reported when the syntax version is greater than the client, not the format library [#6199 @dra27 - fix #6188]
9798

9899
## External dependencies
99100
* Always pass --no-version-check and --no-write-registry to Cygwin setup [#6046 @dra27]

src/format/opamFile.ml

+11-3
Original file line numberDiff line numberDiff line change
@@ -874,9 +874,17 @@ module Syntax = struct
874874
let filename = OpamFilename.to_string filename in
875875
lexbuf.Lexing.lex_curr_p <- { lexbuf.Lexing.lex_curr_p with
876876
Lexing.pos_fname = filename };
877-
try OpamParser.main OpamLexer.token lexbuf filename with
878-
| OpamLexer.Error msg -> error msg
879-
| Parsing.Parse_error -> error "Parse error"
877+
match OpamParser.main OpamLexer.token lexbuf filename with
878+
| {file_contents =
879+
[{pelem = Variable({pelem = "opam-version"; _},
880+
{pelem = String ver; _}); _ };
881+
{pelem = Section {section_kind = {pelem = "#"; _}; _}; _}]; _}
882+
when OpamVersion.(compare (nopatch (of_string ver))
883+
(nopatch OpamVersion.current)) <= 0 ->
884+
error "Parse error"
885+
| opamfile -> opamfile
886+
| exception OpamLexer.Error msg -> error msg
887+
| exception Parsing.Parse_error -> error "Parse error"
880888

881889

882890
let pp_channel filename ic oc =

tests/reftests/lint.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -1267,11 +1267,11 @@ ${BASEDIR}/future/pin-at-two-one.opam: Errors.
12671267
# Return code 1 #
12681268
### opam lint future/pin-at-two-two.opam
12691269
${BASEDIR}/future/pin-at-two-two.opam: Errors.
1270-
error 2: File format error: unsupported or missing file format version; should be 2.0 or older
1270+
error 2: File format error at line 11, column 0: Parse error
12711271
# Return code 1 #
12721272
### opam lint future/pin-at-two-three.opam
12731273
${BASEDIR}/future/pin-at-two-three.opam: Errors.
1274-
error 2: File format error: unsupported or missing file format version; should be 2.0 or older
1274+
error 2: File format error at line 11, column 0: Parse error
12751275
# Return code 1 #
12761276
### opam lint future/pin-at-future.opam
12771277
${BASEDIR}/future/pin-at-future.opam: Errors.

tests/reftests/pin.test

+2-2
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ echo GARBAGE>>"$1"
353353
Parse error [skipped]
354354

355355
[ERROR] Invalid opam file in pin-at-two-two source from file://${BASEDIR}/pin-at-two-two:
356-
error 2: File format error: unsupported or missing file format version; should be 2.0 or older
356+
error 2: File format error at line 11, column 0: Parse error
357357
[ERROR] No package named pin-at-two-two found.
358358
# Return code 5 #
359359
### sh junk.sh pin-at-two-three/pin-at-two-three.opam
@@ -367,7 +367,7 @@ echo GARBAGE>>"$1"
367367
Parse error [skipped]
368368

369369
[ERROR] Invalid opam file in pin-at-two-three source from file://${BASEDIR}/pin-at-two-three:
370-
error 2: File format error: unsupported or missing file format version; should be 2.0 or older
370+
error 2: File format error at line 11, column 0: Parse error
371371
[ERROR] No package named pin-at-two-three found.
372372
# Return code 5 #
373373
### sh junk.sh pin-at-future/pin-at-future.opam

0 commit comments

Comments
 (0)