Skip to content

Commit

Permalink
Fix intToOptimisationLevel dynamic bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
jgotoh committed Nov 4, 2024
1 parent 18ec0e6 commit b69d1c2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions Cabal/src/Distribution/Simple/Compiler.hs
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,18 @@ flagToOptimisationLevel (Just s) = case reads s of

intToOptimisationLevel :: Int -> OptimisationLevel
intToOptimisationLevel i
| i >= fromEnum (minBound :: OptimisationLevel)
&& i <= fromEnum (maxBound :: OptimisationLevel) =
toEnum i
| i >= minLevel && i <= maxLevel = toEnum i
| otherwise =
error $
"Bad optimisation level: "
++ show i
++ ". Valid values are 0..2"
++ ". Valid values are "
++ show minLevel
++ ".."
++ show maxLevel
where
minLevel = fromEnum (minBound :: OptimisationLevel)
maxLevel = i <= fromEnum (maxBound :: OptimisationLevel)

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

Expand Down

0 comments on commit b69d1c2

Please sign in to comment.