Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions Cabal-syntax/src/Distribution/Fields/ParseResult.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,14 @@ runParseResult pr = unPR pr emptyPRState initialCtx failure success
where
initialCtx = PRContext PUnknownSource

failure (PRState warns [] v) = (warns, Left (v, PErrorWithSource PUnknownSource (PError zeroPos "panic") :| []))
failure (PRState warns (err : errs) v) = (warns, Left (v, err :| errs))
failure (PRState warns [] v) = (sortWarns warns, Left (v, PErrorWithSource PUnknownSource (PError zeroPos "panic") :| []))
failure (PRState warns (err : errs) v) = (sortWarns warns, Left (v, err :| errs))

success (PRState warns [] _) x = (warns, Right x)
success (PRState warns [] _) x = (sortWarns warns, Right x)
-- If there are any errors, don't return the result
success (PRState warns (err : errs) v) _ = (warns, Left (v, err :| errs))
success (PRState warns (err : errs) v) _ = (sortWarns warns, Left (v, err :| errs))

sortWarns = sortBy (comparing (pwarningPosition . pwarning))

-- | Chain parsing operations that involve 'IO' actions.
liftParseResult :: (a -> IO (ParseResult src b)) -> ParseResult src a -> IO (ParseResult src b)
Expand Down
4 changes: 2 additions & 2 deletions Cabal-tests/tests/ParserTests/regressions/common.format
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
common.cabal:29:3: Unknown field: import. You should set cabal-version: 2.2 or larger to use common stanzas
common.cabal:20:3: Unknown field: import. You should set cabal-version: 2.2 or larger to use common stanzas
common.cabal:14:1: Ignoring section: common. You should set cabal-version: 2.2 or larger to use common stanzas.
common.cabal:20:3: Unknown field: import. You should set cabal-version: 2.2 or larger to use common stanzas
common.cabal:29:3: Unknown field: import. You should set cabal-version: 2.2 or larger to use common stanzas
cabal-version: >=1.10
name: common
version: 0
Expand Down
2 changes: 1 addition & 1 deletion Cabal-tests/tests/ParserTests/regressions/elif.format
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
elif.cabal:19:3: invalid subsection "else"
elif.cabal:17:3: invalid subsection "elif". You should set cabal-version: 2.2 or larger to use elif-conditionals.
elif.cabal:19:3: invalid subsection "else"
cabal-version: >=1.10
name: elif
version: 0
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
wl-pprint-indef.cabal:28:3: The field "mixins" is available only since the Cabal specification version 2.0. This field will be ignored.
wl-pprint-indef.cabal:27:3: The field "signatures" is available only since the Cabal specification version 2.0. This field will be ignored.
wl-pprint-indef.cabal:23:3: The field "mixins" is available only since the Cabal specification version 2.0. This field will be ignored.
wl-pprint-indef.cabal:27:3: The field "signatures" is available only since the Cabal specification version 2.0. This field will be ignored.
wl-pprint-indef.cabal:28:3: The field "mixins" is available only since the Cabal specification version 2.0. This field will be ignored.
cabal-version: >=1.6
name: wl-pprint-indef
version: 1.2
Expand Down
10 changes: 10 additions & 0 deletions changelog.d/issue-11269.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
synopsis: Fix parse warnings being emitted in reverse order
packages: [Cabal-syntax]
prs: 11479
issues: 11269
---

Parse warnings were prepended to the accumulator list, causing them to
be emitted in reverse file order. They are now sorted so they come out
in file order, consistent with GHC's behavior.
Loading