Skip to content

Commit 4061bfa

Browse files
authored
Merge pull request #5994 from haskell/hide-read
Don't export 'read': panic explicitly
2 parents a967887 + a697bb1 commit 4061bfa

File tree

9 files changed

+17
-15
lines changed

9 files changed

+17
-15
lines changed

Cabal/Distribution/Compat/Prelude.hs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,15 @@ module Distribution.Compat.Prelude (
9191

9292
-- * Text.PrettyPrint
9393
(<<>>),
94+
95+
-- * Text.Read
96+
readMaybe,
9497
) where
9598
-- We also could hide few partial function
9699
import Prelude as BasePrelude hiding
97100
( IO, mapM, mapM_, sequence, null, length, foldr, any, all
101+
-- partial functions
102+
, read
98103
#if MINVER_base_411
99104
-- As of base 4.11.0.0 Prelude exports part of Semigroup(..).
100105
-- Hide this so we instead rely on Distribution.Compat.Semigroup.
@@ -140,6 +145,7 @@ import Data.Maybe
140145
import Data.String (IsString (..))
141146
import Data.Int
142147
import Data.Word
148+
import Text.Read (readMaybe)
143149

144150
import qualified Text.PrettyPrint as Disp
145151

Cabal/Distribution/Simple/InstallDirs.hs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,10 @@ type PathTemplateEnv = [(PathTemplateVariable, PathTemplate)]
395395
-- | Convert a 'FilePath' to a 'PathTemplate' including any template vars.
396396
--
397397
toPathTemplate :: FilePath -> PathTemplate
398-
toPathTemplate = PathTemplate . read -- TODO: eradicateNoParse
398+
toPathTemplate fp = PathTemplate
399+
. fromMaybe (error $ "panic! toPathTemplate " ++ show fp)
400+
. readMaybe -- TODO: eradicateNoParse
401+
$ fp
399402

400403
-- | Convert back to a path, any remaining vars are included
401404
--

Cabal/Distribution/Simple/PreProcess/Unlit.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ classify ('#':s) = case tokens s of
3737
&& length file >= 2
3838
&& head file == '"'
3939
&& last file == '"'
40-
-> Line (read line) (tail (init file)) -- TODO:eradicateNoParse
40+
-- this shouldn't fail as we tested for 'all isDigit'
41+
-> Line (fromMaybe (error $ "panic! read @Int " ++ show line) $ readMaybe line) (tail (init file)) -- TODO:eradicateNoParse
4142
_ -> CPP s
4243
where tokens = unfoldr $ \str -> case lex str of
4344
(t@(_:_), str'):_ -> Just (t, str')

Cabal/Distribution/Simple/Program/GHC.hs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -242,11 +242,6 @@ normaliseGhcArgs (Just ghcVersion) PackageDescription{..} ghcArgs
242242
parseInt :: String -> Maybe Int
243243
parseInt = readMaybe . dropEq
244244

245-
readMaybe :: Read a => String -> Maybe a
246-
readMaybe s = case reads s of
247-
[(x, "")] -> Just x
248-
_ -> Nothing
249-
250245
dropEq :: String -> String
251246
dropEq ('=':s) = s
252247
dropEq s = s

Cabal/Distribution/Simple/Test/LibV09.hs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ runTest pkg_descr lbi clbi flags suite = do
123123
(unUnqualComponentName $ testSuiteName l) (testLogs l)
124124
-- Generate TestSuiteLog from executable exit code and a machine-
125125
-- readable test log
126-
suiteLog <- fmap ((\l -> l { logFile = finalLogName l }) . read) -- TODO: eradicateNoParse
126+
suiteLog <- fmap (\s -> (\l -> l { logFile = finalLogName l })
127+
. fromMaybe (error $ "panic! read @TestSuiteLog " ++ show s) $ readMaybe s) -- TODO: eradicateNoParse
127128
$ readFile tempLog
128129

129130
-- Write summary notice to log file indicating start of test suite
@@ -219,7 +220,7 @@ simpleTestStub m = unlines
219220
-- of detectable errors when Cabal is compiled.
220221
stubMain :: IO [Test] -> IO ()
221222
stubMain tests = do
222-
(f, n) <- fmap read getContents -- TODO: eradicateNoParse
223+
(f, n) <- fmap (\s -> fromMaybe (error $ "panic! read " ++ show s) $ readMaybe s) getContents -- TODO: eradicateNoParse
223224
dir <- getCurrentDirectory
224225
results <- (tests >>= stubRunTests) `CE.catch` errHandler
225226
setCurrentDirectory dir

Cabal/tests/UnitTests/Distribution/Version.hs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import Test.QuickCheck.Utils
2424

2525
import Data.Maybe (fromJust)
2626
import Data.Function (on)
27-
import Text.Read (readMaybe)
2827

2928
versionTests :: [TestTree]
3029
versionTests =

cabal-install/Distribution/Client/Compat/Prelude.hs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,7 @@
1313
module Distribution.Client.Compat.Prelude
1414
( module Distribution.Compat.Prelude.Internal
1515
, Prelude.IO
16-
, readMaybe
1716
) where
1817

1918
import Prelude (IO)
2019
import Distribution.Compat.Prelude.Internal hiding (IO)
21-
import Text.Read
22-
( readMaybe )

cabal-install/Distribution/Deprecated/Text.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module Distribution.Deprecated.Text (
2323
) where
2424

2525
import Distribution.Client.Compat.Prelude
26-
import Prelude ()
26+
import Prelude (read)
2727

2828
import Distribution.Deprecated.ReadP ((<++))
2929
import qualified Distribution.Deprecated.ReadP as Parse

cabal-install/main/Main.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1220,7 +1220,7 @@ userConfigAction ucflags extraArgs globalFlags = do
12201220
win32SelfUpgradeAction :: Win32SelfUpgradeFlags -> [String] -> Action
12211221
win32SelfUpgradeAction selfUpgradeFlags (pid:path:_extraArgs) _globalFlags = do
12221222
let verbosity = fromFlag (win32SelfUpgradeVerbosity selfUpgradeFlags)
1223-
Win32SelfUpgrade.deleteOldExeFile verbosity (read pid) path -- TODO: eradicateNoParse
1223+
Win32SelfUpgrade.deleteOldExeFile verbosity (fromMaybe (error $ "panic! read pid=" ++ show pid) $ readMaybe pid) path -- TODO: eradicateNoParse
12241224
win32SelfUpgradeAction _ _ _ = return ()
12251225

12261226
-- | Used as an entry point when cabal-install needs to invoke itself

0 commit comments

Comments
 (0)