Open
Description
If the module in main-is
has a name and there is another module that has no explicit name (no module
header), then the other module is picked as main module.
Bar.hs
main = putStrLn "I am the shady main..."
Foo.hs
module Foo where
main = putStrLn "I am the real main!"
wrong-main.cabal
cabal-version: 1.12
name: wrong-main
version: 0.0.0
build-type: Simple
executable wrong-main
main-is: Foo.hs
other-modules:
Bar
Paths_wrong_main
hs-source-dirs:
./
build-depends:
base
default-language: Haskell2010
$ cabal run
...
I am the shady main...
Packaged reproducer: wrong-main.tgz
Analysis: It seems Cabal calls GHC this way:
ghc --make -fbuilding-cabal-package -O -static ... -XHaskell2010 ./Foo.hs Bar Paths_wrong_main ...
The correct result can be obtained by adding -main-is Foo
:
ghc --make -main-is Foo Bar.hs Foo.hs
I suppose the difficulty is to extract the module name Foo
from Foo.hs
, since -main-is
does not accept a file, just a qualified (module) name.
(I am having a dejavu here, but I couldn't find a report for this issue.)
Stack has the same problem: