GHCi can't evaluate expressions with a broken Main module
Summary
Using GHC 8.2 and below, if you are in ghci
with module Main
loaded, and reload with a broken file, the old module remains in scope. In GHC 8.4 and above, the module no longer works.
Steps to reproduce
- Create a file
bug.hs
which is empty - Run
ghci bug.hs
- Change
bug.hs
to readimport
- Type
:reload
in ghci, it displays a message about a parse error - Type
1
in ghci, it displays a message about not being able to find moduleMain
Expected behavior
In GHC 8.2 and below the final step 5 prints out 1
. If you change it to read impor
then it works. It seems to be only if the module has enough of a header to guess the module name then it results in a prompt where the failed load breaks all subsequent commands. It would be nice if a failed load happens then things remain in a working state.
Impact
This bug was reported via ghcid
: https://github.com/ndmitchell/ghcid/issues/290. The ghcid
program sends a :reload
followed by putStrLn "done"
and waits for the done
to appear. In most circumstances that works. In the above case it doesn't.
Note that if ghci
could be persuaded to print something on both stdout and stderr (so I know both streams are finished), then ghcid
wouldn't use putStrLn
.