Setting -XTemplateHaskell in GHCi unloads modules that were specified on the command-line
:set -XTemplateHaskell in
ghci (in some situations) has two side effects:
- The scope is cleared
- Any modules that were specified on the command line are unloaded
While (1) is inconvenient, I have a hard time considering (2) as acceptable.
This also breaks
I haven't been able to reproduce the issue without
cabal exec (e.g. with a
.ghc.enviroment-file). Not exactly sure what's the difference.
package flags have changed, resetting and loading new packages...
I guess that it's somehow related to this code: https://gitlab.haskell.org/ghc/ghc/-/blob/master/ghc/GHCi/UI.hs#L3120
Steps to reproduce
-- foo.cabal cabal-version: 3.6 name: foo version: 0.0.0 library build-depends: base
-- Foo.hs module Foo where foo :: Int foo = 23
$ cabal build . && cabal exec ghci Foo.hs ghci> foo 23 ghci> :set -XTemplateHaskell package flags have changed, resetting and loading new packages... ghci> foo
foo should still be in scope:
ghci> foo 23
foo is not in scope:
ghci> foo <interactive>:3:1: error: Variable not in scope: foo
- GHC version used: 9.2.1
$ cabal --version && uname -s -m cabal-install version 220.127.116.11 compiled using version 18.104.22.168 of the Cabal library Linux x86_64