GHC doesn't respect the search path when loading "entry points" modules.
Suppose we have (slightly ambigupus setup):
A library in lib
: lib/Setup.hs
module Setup where
val :: String
val = "in src"
A setup script in: Setup.hs
module Main where
main :: IO ()
main = putStrLn "run"
val :: String
val = "in top directory"
Now if I try to load (or compile) the library by specifying search path
to be just src
directory (-i -isrc
), and a module name Setup
% ghci -i -isrc Setup
GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Main ( Setup.hs, interpreted )
Ok, one module loaded.
*Main>
... the GHCi loads the setup script, not a library module!
If there weren't Setup.hs
in root directory, the correct module is loaded
% ghci -i -isrc Setup
GHCi, version 8.6.5: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Setup ( src/Setup.hs, interpreted )
Ok, one module loaded.
*Setup>
So the search path is respected, but it seems that CWD directory is additionally used to find "entry compilation targets" specified on the command line.
The issue is reproducinble with GHC-7.0..GHC-8.10 Originally reported as https://github.com/haskell/cabal/issues/7159