Import suggestions don't work in GHCi
Summary
While working on !5763 (closed), I noticed that GHCi doesn't report suggestions about adding things to the import list and similar suggestions, for example:
import Control.Monad (sequence)
x = guard
results in
Variable not in scope: guard
Perhaps you want to add ‘guard’ to the import list
in the import of ‘Control.Monad’ (T19843j.hs:3:1-31).
when compiled with GHC or loaded into GHCi via :load
, but when the same code is entered directly in GHCi, the error message is merely
Variable not in scope: guard
This happens because at the point the error reporting functions are called in GHCi, calling getImports
to get the imports from the TcM
results in an empty ModuleEnv
. I've tracked this up to reportUnsolved
, at which point it's already the case that getImports
via GHC finds the imports, but getImports
via GHCi doesn't. I'm not sure though how to find the cause of this discrepancy from here.
Environment
- GHC version used: 9.3.20210513
Optional:
- Operating System: Arch on WSL2 on Windows 10
- System Architecture: x86_64