Skip to content

fix(Cabal): Fix parsing of boolean values to debug-info - #12202

Open
zlonast wants to merge 4 commits into
haskell:masterfrom
zlonast:zlonast/boolean-debug-info
Open

fix(Cabal): Fix parsing of boolean values to debug-info#12202
zlonast wants to merge 4 commits into
haskell:masterfrom
zlonast:zlonast/boolean-debug-info

Conversation

@zlonast

@zlonast zlonast commented Aug 2, 2026

Copy link
Copy Markdown
Collaborator

fix: #12140

debug-info: False ​​are treated as NoDebugInfo, and debug-info: True ​​are treated as NormalDebugInfo


Template Α: This PR modifies behaviour or interface

Include the following checklist in your PR:

@zlonast
zlonast requested a review from philderbeast August 21, 2026 12:47
Comment on lines +385 to +398
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)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is very similar to intToOptimisationLevel. Maybe we could use a safeIntToEnum or intToEnum function to reduce the duplication?

safeIntToEnum :: (Enum a, Bounded a) => Int -> Maybe a
intToEnum :: (Enum a, Bounded a) => Int -> a

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no such functions, I took what I found in safe

intToEnum :: (Show a, Enum a, Bounded a) => String -> Int -> a
intToEnum str i =
  let res = toEnum i
      maxLevel = maxBound `asTypeOf` res
      minLevel = minBound `asTypeOf` res
   in if i >= fromEnum minLevel && i <= fromEnum maxLevel
        then res
        else
          error $
            "Bad "
              ++ str
              ++ ": "
              ++ show i
              ++ ". Valid values are "
              ++ show minLevel
              ++ ".."
              ++ show maxLevel

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are no such functions

I should have been clearer. I was only suggesting to possibly write helper functions with those signatures. Not even sure if that is possible.

Comment thread changelog.d/12202.md Outdated
Comment on lines +2 to +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`.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are odd zero-width characters in this file:

$ cat -A changelog.d/12202.md
---$
synopsis: Fix parsing of boolean values M-bM-^@M-^KM-bM-^@M-^Kto debug-info$
packages: [Cabal]$
prs: 12202$
issues: 12140$
---$
$
`False` values M-bM-^@M-^KM-bM-^@M-^Kare treated as `NoDebugInfo`, and `True` values M-bM-^@M-^KM-bM-^@M-^Kare treated as `NormalDebugInfo`.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure how this happened

@philderbeast philderbeast left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we're parsing booleans for debug-info in the project, would that also apply to the command line? If not, is error the best message?

$ cabal build --help
...
--enable-debug-info[=n]        Emit debug info (n is 0--3, default is 0)
--disable-debug-info           Don't emit debug info
$ cabal run cabal-install:exe:cabal -- build all --dry-run \
   --enable-debug-info=True
...
Can't parse debug info level True

HasCallStack backtrace:
  error, called at src/Distribution/Simple/Compiler.hs:383:8 in
  Cabal-3.19.0.0-inplace:Distribution.Simple.Compiler

$ cabal-3.18.1.0 build all --dry-run --enable-debug-info=True
Can't parse debug info level True
CallStack (from HasCallStack):
  error, called at src/Distribution/Simple/Compiler.hs:392:8 in
  Cabal-3.18.1.0-inplace:Distribution.Simple.Compiler

@zlonast

zlonast commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator Author

@philderbeast Thanks for such a detailed review, yes, I think this approach should be applied to the command line as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parsec project parser can't parse debug-info boolean

3 participants