File tree Expand file tree Collapse file tree 8 files changed +85
-7
lines changed
cabal-install/src/Distribution
cabal-testsuite/PackageTests/ProjectConfig/FieldStanzaConfusion Expand file tree Collapse file tree 8 files changed +85
-7
lines changed Original file line number Diff line number Diff line change 1
1
{-# LANGUAGE ExistentialQuantification #-}
2
2
{-# LANGUAGE NamedFieldPuns #-}
3
3
{-# LANGUAGE RankNTypes #-}
4
+ {-# LANGUAGE ScopedTypeVariables #-}
5
+ {-# LANGUAGE TypeApplications #-}
4
6
5
7
-----------------------------------------------------------------------------
6
8
@@ -53,6 +55,7 @@ import Distribution.Deprecated.ParseUtils
53
55
( Field (.. )
54
56
, FieldDescr (.. )
55
57
, LineNo
58
+ , PError (.. )
56
59
, ParseResult (.. )
57
60
, liftField
58
61
, lineNo
@@ -292,13 +295,16 @@ parseFieldsAndSections fieldDescrs sectionDescrs fgSectionDescrs =
292
295
setField a (F line name value) =
293
296
case Map. lookup name fieldMap of
294
297
Just (FieldDescr _ _ set) -> set line value a
295
- Nothing -> do
296
- warning $
297
- " Unrecognized field '"
298
- ++ name
299
- ++ " ' on line "
300
- ++ show line
301
- return a
298
+ Nothing ->
299
+ case Left <$> Map. lookup name sectionMap <|> Right <$> Map. lookup name fgSectionMap of
300
+ Just _ -> ParseFailed $ FieldShouldBeStanza name line
301
+ Nothing -> do
302
+ warning $
303
+ " Unrecognized field '"
304
+ ++ name
305
+ ++ " ' on line "
306
+ ++ show line
307
+ return a
302
308
setField a (Section line name param fields) =
303
309
case Left <$> Map. lookup name sectionMap <|> Right <$> Map. lookup name fgSectionMap of
304
310
Just (Left (SectionDescr _ fieldDescrs' sectionDescrs' _ set sectionEmpty)) -> do
Original file line number Diff line number Diff line change @@ -91,6 +91,7 @@ data PError
91
91
= AmbiguousParse String LineNo
92
92
| NoParse String LineNo
93
93
| TabsError LineNo
94
+ | FieldShouldBeStanza String LineNo
94
95
| FromString String (Maybe LineNo )
95
96
deriving (Eq , Show )
96
97
@@ -186,6 +187,10 @@ locatedErrorMsg (NoParse f n) =
186
187
, " Parse of field '" ++ f ++ " ' failed."
187
188
)
188
189
locatedErrorMsg (TabsError n) = (Just n, " Tab used as indentation." )
190
+ locatedErrorMsg (FieldShouldBeStanza name lineNumber) =
191
+ ( Just lineNumber
192
+ , " '" ++ name ++ " ' is a stanza, not a field. Remove the trailing ':' to parse a stanza."
193
+ )
189
194
locatedErrorMsg (FromString s n) = (n, s)
190
195
191
196
syntaxError :: LineNo -> String -> ParseResult a
Original file line number Diff line number Diff line change
1
+ # cabal build
2
+ Error: [Cabal-7090]
3
+ Error parsing project file <ROOT>/cabal.project:4:
4
+ 'source-repository-package' is a stanza, not a field. Remove the trailing ':' to parse a stanza.
Original file line number Diff line number Diff line change
1
+ packages : .
2
+
3
+ -- This is an error; a trailing `:` is syntax for a field, not a stanza!
4
+ source-repository-package :
5
+ type : git
6
+ location : https://github.com/haskell-hvr/Only
Original file line number Diff line number Diff line change
1
+ import Test.Cabal.Prelude
2
+
3
+ main = cabalTest $ do
4
+ result <- fails $ cabal' " build" []
5
+ assertOutputContains " Error parsing project file" result
6
+ assertOutputContains " 'source-repository-package' is a stanza, not a field." result
Original file line number Diff line number Diff line change
1
+ module MyLib (someFunc ) where
2
+
3
+ someFunc :: IO ()
4
+ someFunc = putStrLn " someFunc"
Original file line number Diff line number Diff line change
1
+ cabal-version : 3.0
2
+ name : test
3
+ version : 0.1.0.0
4
+ license : NONE
5
+
6
+ maintainer : Rebecca Turner
7
+ build-type : Simple
8
+
9
+ library
10
+ exposed-modules : MyLib
11
+ build-depends : base
12
+ hs-source-dirs : src
13
+ default-language : Haskell2010
Original file line number Diff line number Diff line change
1
+ ---
2
+ synopsis: "A trailing colon after a stanza name in `cabal.project` is now an error"
3
+ packages: [cabal-install]
4
+ prs: 10525
5
+ ---
6
+
7
+ It is now a hard error to use a trailing colon after a stanza name in
8
+ `cabal.project` or `*.cabal` files:
9
+
10
+ ```
11
+ packages: .
12
+
13
+ source-repository-package:
14
+ type: git
15
+ location: https://github.com/haskell/cabal
16
+ tag: f34aba976a60940295f41b6649674e9568893894
17
+ ```
18
+
19
+ ```
20
+ $ cabal build
21
+ Error parsing project file cabal.project:3:
22
+ 'source-repository-package' is a stanza, not a field. Remove the trailing ':' to parse a stanza.
23
+ ```
24
+
25
+ Previously, the warning message was easily ignored and somewhat misleading, as
26
+ the difference between a stanza and a field is not immediately obvious to
27
+ Haskellers used to config languages like JSON and YAML (which don't distinguish
28
+ between fields which have string or list values and stanzas which have nested
29
+ fields):
30
+
31
+ ```
32
+ Warning: cabal.project: Unrecognized field
33
+ 'source-repository-package' on line 3
34
+ ```
You can’t perform that action at this time.
0 commit comments