fix(Cabal): Fix parsing of boolean values to debug-info - #12202
Conversation
| 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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
| 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`. |
There was a problem hiding this comment.
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`.
There was a problem hiding this comment.
I'm not sure how this happened
philderbeast
left a comment
There was a problem hiding this comment.
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
|
@philderbeast Thanks for such a detailed review, yes, I think this approach should be applied to the command line as well. |
fix: #12140
debug-info: Falseare treated asNoDebugInfo, anddebug-info: Trueare treated asNormalDebugInfoTemplate Α: This PR modifies behaviour or interface
Include the following checklist in your PR:
significance: significantin the changelog file.