diff options
author | Reid Barton <rwbarton@gmail.com> | 2014-12-23 15:22:01 -0500 |
---|---|---|
committer | Reid Barton <rwbarton@gmail.com> | 2014-12-23 15:31:41 -0500 |
commit | 878910e1c4520732ab9d8372c1c81f00d484e48f (patch) | |
tree | 7503de9cd2ea6dd2777670df3429b51b2cab9c58 /ghc | |
parent | 7a2c9dde24b72fe53216881867d5543e5a6f756c (diff) | |
download | haskell-878910e1c4520732ab9d8372c1c81f00d484e48f.tar.gz |
Make ghc -e not exit on valid import commands (#9905)
Summary:
Some Trues and Falses were mixed up due to Bool being used in
different senses in different parts of GHCi.
Test Plan: harbormaster; validate
Reviewers: austin
Reviewed By: austin
Subscribers: carter, thomie
Differential Revision: https://phabricator.haskell.org/D581
GHC Trac Issues: #9905
Conflicts:
ghc/InteractiveUI.hs
Diffstat (limited to 'ghc')
-rw-r--r-- | ghc/GhciMonad.hs | 1 | ||||
-rw-r--r-- | ghc/InteractiveUI.hs | 22 |
2 files changed, 15 insertions, 8 deletions
diff --git a/ghc/GhciMonad.hs b/ghc/GhciMonad.hs index 89c2028960..f57fbba101 100644 --- a/ghc/GhciMonad.hs +++ b/ghc/GhciMonad.hs @@ -63,6 +63,7 @@ import Control.Applicative (Applicative(..)) ----------------------------------------------------------------------------- -- GHCi monad +-- the Bool means: True = we should exit GHCi (:quit) type Command = (String, String -> InputT GHCi Bool, CompletionFunc GHCi) data GHCiState = GHCiState diff --git a/ghc/InteractiveUI.hs b/ghc/InteractiveUI.hs index d478336c36..ce73c48ce5 100644 --- a/ghc/InteractiveUI.hs +++ b/ghc/InteractiveUI.hs @@ -729,7 +729,11 @@ runCommands' eh sourceErrorHandler gCmd = do when (not success) $ maybe (return ()) lift sourceErrorHandler runCommands' eh sourceErrorHandler gCmd --- | Evaluate a single line of user input (either :<command> or Haskell code) +-- | Evaluate a single line of user input (either :<command> or Haskell code). +-- A result of Nothing means there was no more input to process. +-- Otherwise the result is Just b where b is True if the command succeeded; +-- this is relevant only to ghc -e, which will exit with status 1 +-- if the commmand was unsuccessful. GHCi will continue in either case. runOneCommand :: (SomeException -> GHCi Bool) -> InputT GHCi (Maybe String) -> InputT GHCi (Maybe Bool) runOneCommand eh gCmd = do @@ -740,14 +744,14 @@ runOneCommand eh gCmd = do case mb_cmd1 of Nothing -> return Nothing Just c -> ghciHandle (\e -> lift $ eh e >>= return . Just) $ - handleSourceError printErrorAndKeepGoing + handleSourceError printErrorAndFail (doCommand c) -- source error's are handled by runStmt -- is the handler necessary here? where - printErrorAndKeepGoing err = do + printErrorAndFail err = do GHC.printException err - return $ Just True + return $ Just False -- Exit ghc -e, but not GHCi noSpace q = q >>= maybe (return Nothing) (\c -> case removeSpaces c of @@ -890,16 +894,18 @@ declPrefixes dflags = keywords ++ concat opt_keywords , ["deriving " | xopt Opt_StandaloneDeriving dflags] ] --- | Entry point to execute some haskell code from user +-- | Entry point to execute some haskell code from user. +-- The return value True indicates success, as in `runOneCommand`. runStmt :: String -> SingleStep -> GHCi Bool runStmt stmt step - -- empty + -- empty; this should be impossible anyways since we filtered out + -- whitespace-only input in runOneCommand's noSpace | null (filter (not.isSpace) stmt) - = return False + = return True -- import | stmt `looks_like` "import " - = do addImportToContext stmt; return False + = do addImportToContext stmt; return True | otherwise = do dflags <- getDynFlags |