Skip to content

Exit with failure when -e fails (fix #18411 #9916 #17560)

Alex D requested to merge nineonine/ghc:T18411 into master

fixes #18411 (closed) #9916 (closed) #17560 (closed)

GHCi UI code was updated to exit/fail with error code 1 if something has gone wrong in expression evaluation mode. This makes sense because this meets expectations/necessities of users that use this mode when writing scripts.

A few things were introduced to implement this:

  1. Previously, a Bool data type was used to make decision whether execution should fail (ghc -e) or continue (regular repl mode). Instead of bland Bool new ADT was introduced to denote the outcome of ghci command execution:
data CmdExecOutcome
  = CleanExit
  | CmdSuccess
  | CmdFailure

This is now used as a return type in many command actions. I only scratched the surface and wasn't able to rip out this Bool. If this design is acceptable, I will create a follow-up ticket to eliminate this Bool entirely and replace it with newly introduced ADT (this implies refactoring runOneCommand, runStmt and friends).

  1. A few new helpers were introduced and scattered where necessary to ensure the desired execution outcome. The idea is to check GHCi state (specifically, the ghc_e field) and conditionally throw ExitFailure.

  2. Regression tests were added to check all necessary code paths.

Edited by Alex D

Merge request reports