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
30 changes: 20 additions & 10 deletions Cabal/src/Distribution/Simple/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -371,22 +371,32 @@ instance Parsec DebugInfoLevel where
parsec = parsecDebugInfoLevel

parsecDebugInfoLevel :: CabalParsing m => m DebugInfoLevel
parsecDebugInfoLevel = flagToDebugInfoLevel . pure <$> parsecToken
parsecDebugInfoLevel = boolParser <|> intParser
where
boolParser = bool NoDebugInfo NormalDebugInfo <$> parsec
intParser = intToDebugInfoLevel <$> integral

flagToDebugInfoLevel :: Maybe String -> DebugInfoLevel
flagToDebugInfoLevel Nothing = NormalDebugInfo
flagToDebugInfoLevel (Just s) = case reads s of
[(i, "")]
| i >= fromEnum (minBound :: DebugInfoLevel)
&& i <= fromEnum (maxBound :: DebugInfoLevel) ->
toEnum i
| otherwise ->
error $
"Bad debug info level: "
++ show i
++ ". Valid values are 0..3"
[(i, "")] -> intToDebugInfoLevel i
_ -> error $ "Can't parse debug info level " ++ s

intToDebugInfoLevel :: Int -> DebugInfoLevel
intToDebugInfoLevel i
| i >= minLevel && i <= maxLevel = toEnum i
| otherwise =
error $
"Bad debug info level: "
++ show i
++ ". Valid values are "
++ show minLevel
++ ".."
++ show maxLevel
where
minLevel = fromEnum (minBound :: DebugInfoLevel)
maxLevel = fromEnum (maxBound :: DebugInfoLevel)

-- ------------------------------------------------------------

-- * Languages and Extensions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,6 @@ In order, the following would be built:
# cabal build
Warnings found while parsing the project file, cabal.boolean.project:
- cabal.boolean.project:2:1: The field "debug-info" is specified more than once at positions 2:1, 3:1
Build profile: -w ghc-<GHCVER> -O1
In order, the following would be built:
- debug-info-0 (lib) (first run)
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ main = cabalTest . recordMode RecordMarked $ do
numeric <- cabal' "build" ["--project-file=cabal.numeric.project", "--dry-run"]
assertOutputDoesNotContain errMsg numeric

boolean <- fails $ cabal' "build" ["--project-file=cabal.boolean.project", "--dry-run"]
-- TODO: When fixed, change this to assertOutputDoesNotContain.
assertOutputContains errMsg boolean
pure ()
boolean <- cabal' "build" ["--project-file=cabal.boolean.project", "--dry-run"]
assertOutputDoesNotContain errMsg boolean
8 changes: 8 additions & 0 deletions changelog.d/12202.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
synopsis: Fix parsing of boolean values ​​to debug-info
packages: [Cabal]
prs: 12202
issues: 12140
---

`False` values ​​are treated as `NoDebugInfo`, and `True` values ​​are treated as `NormalDebugInfo`.
Loading