Skip to content

Commit

Permalink
Detect future syntax errors in the Syntax helper
Browse files Browse the repository at this point in the history
Repository parsing and linting use a slightly different parsing route
which wasn't checking for future syntax errors.
  • Loading branch information
dra27 committed Sep 16, 2024
1 parent bbb8a42 commit 4fbaf02
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions master_changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
11 changes: 8 additions & 3 deletions src/format/opamFile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
4 changes: 2 additions & 2 deletions tests/reftests/lint.test
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 4fbaf02

Please sign in to comment.