Skip to content

Commit 6041ae6

Browse files
committed
Avoid partial last in autogen Paths_<pkg>.hs
1 parent 47139c5 commit 6041ae6

File tree

2 files changed

+17
-3
lines changed
  • Cabal/src/Distribution/Simple/Build/PathsModule
  • changelog.d

2 files changed

+17
-3
lines changed

Cabal/src/Distribution/Simple/Build/PathsModule/Z.hs

+7-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ render z_root = execWriter $ do
6969
return ()
7070
tell "\n"
7171
tell "import qualified Control.Exception as Exception\n"
72-
tell "import qualified Data.List as List\n"
7372
tell "import Data.Version (Version(..))\n"
7473
tell "import System.Environment (getEnv)\n"
7574
tell "import Prelude\n"
@@ -306,9 +305,14 @@ render z_root = execWriter $ do
306305
tell "joinFileName \"\" fname = fname\n"
307306
tell "joinFileName \".\" fname = fname\n"
308307
tell "joinFileName dir \"\" = dir\n"
309-
tell "joinFileName dir fname\n"
310-
tell " | isPathSeparator (List.last dir) = dir ++ fname\n"
308+
tell "joinFileName dir@(c:cs) fname\n"
309+
tell " | isPathSeparator (lastChar c cs) = dir ++ fname\n"
311310
tell " | otherwise = dir ++ pathSeparator : fname\n"
311+
tell " where\n"
312+
-- We do not use Data.List.NonEmpty.last, as that would limit the module to
313+
-- base >= 4.9.0.0 (GHC >= 8.0.1).
314+
tell " lastChar x [] = x\n"
315+
tell " lastChar _ (x:xs) = lastChar x xs\n"
312316
tell "\n"
313317
tell "pathSeparator :: Char\n"
314318
if (zIsWindows z_root)

changelog.d/pr-10432

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
synopsis: Avoid partial `Data.List.last` in autogenerated `Paths_<pkg>.hs`
2+
packages: Cabal
3+
prs: #10432
4+
significance:
5+
6+
description: {
7+
8+
- Autogenerated `Paths_<pkg>.hs` now avoids use of the partial function `Data.List.last`.
9+
10+
}

0 commit comments

Comments
 (0)