Skip to content

-fdefer-diagnostics causes cabal repl to omit diagnostics when reloading modules

Summary

We ran into an issue where ghcid was not working due when we enabled -fdefer-diagnostics flag. We were able to narrow it down to an issue with cabal repl. Specifically, here is the symptom of the problem:

$ cabal repl

[3446 of 3446] Compiling Foo        ( src/Foo.hs, interpreted )

src/Foo.hs:3:1: error:
    Could not find module 'Data.Time.Cloc'
    Perhaps you meant Data.Time.Clock (from time-1.12.2)
    Use -v (or `:set -v` in ghci) to see a list of the files searched for.
  |
3 | import Data.Time.Cloc
  | ^^^^^^^^^^^^^^^^^^^^^
Failed, 3443 modules loaded.
ghci> :reload
[1632 of 3446] Compiling Foo ( src/Foo.hs, interpreted )
Failed, 3443 modules loaded.
ghci> 

The first time the modules are loaded (with -fdefer-diagnostics enabled), the diagnostic error message is displayed. When the modules are reloaded using the :reload command they don't display the error the second time around.

This causes issues for ghcid (since it parses the diagnostic error messages emitted by cabal repl), so ghcid reports that nothing is wrong because no new diagnostics were emitted when reloading the modules.

Disabling -fdefer-diagnostics (either by omitting the flag or adding a superseding -fno-defer-diagnostics flag) fixes the problem and both cabal repl and ghcid give the expected behavior.

Steps to reproduce

I attempted to minimize this example, but I was unable to do so. I tested using a two module cabal project configured to use ghc-options: -fdefer-diagnostics and I was unable to reproduce this. We've only seen this error in the context of our much larger internal work package. However, we still wanted to report this just in case others run into this problem so that they know what the work-around is.

Expected behavior

What do you expect the reproducer described above to do?

I expect cabal repl to always display the error messages again when reloading modules, even if -fdefer-diagnostics is enabled.

Environment

  • GHC version used: ghc-9.4.2 with this fix

Optional:

  • Operating System: macOS
  • System Architecture: aarch64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information