`ghci -fobject-code SomeSourceFile.hs` forgets commandline-defined variables with separate type signatures
Summary
The title says it all. If you start GHCi with a specified source file and -fobject-code
, your GHCi instance forgets variables defined on command line with separate type signatures. According to my quick search, this kind of problem was addressed by the likes of #12091 (closed), which are marked as resolved, but it looks like there is more to do.
Steps to reproduce
$ echo "main = return () :: IO ()" > Test.hs
$ ghci-9.2.7 -fobject-code Test.hs
GHCi, version 9.2.7: https://www.haskell.org/ghc/ :? for help
Ok, one module loaded.
ghci> :{
ghci| a :: Int
ghci| a = 3
ghci| :}
ghci> a
<interactive>:5:1: error: Variable not in scope: a
ghci> b :: Int; b = 3
ghci> b
<interactive>:7:1: error: Variable not in scope: b
ghci> c = 3; c :: Int
ghci> c
<interactive>:9:1: error: Variable not in scope: c
ghci> d = 3 :: Int
ghci> d
3
ghci> let e :: Int; e = 3
ghci> e
3
For comparison, without any specified source file, we get expected results:
$ ghci-9.2.7 -fobject-code
GHCi, version 9.2.7: https://www.haskell.org/ghc/ :? for help
ghci> :{
ghci| a :: Int
ghci| a = 3
ghci| :}
ghci> a
3
ghci> b :: Int; b = 3
ghci> b
3
ghci> c = 3; c :: Int
ghci> c
3
ghci> d = 3 :: Int
ghci> d
3
ghci> let e :: Int; e = 3
ghci> e
3
Expected behavior
$ echo "main = return () :: IO ()" > Test.hs
$ ghci-9.2.7 -fobject-code Test.hs
GHCi, version 9.2.7: https://www.haskell.org/ghc/ :? for help
Ok, one module loaded.
ghci> :{
ghci| a :: Int
ghci| a = 3
ghci| :}
ghci> a
3
ghci> b :: Int; b = 3
ghci> b
3
ghci> c = 3; c :: Int
ghci> c
3
ghci> d = 3 :: Int
ghci> d
3
ghci> let e :: Int; e = 3
ghci> e
3
Environment
- GHC version used: 9.4.4, 9.2.7, 8.8.4
Optional:
- Operating System: MacOS 13.2.1
- System Architecture: x86-64