You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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
moduleFoowhere
main =putStrLn"I am the real main!"
wrong-main.cabal
cabal-version: 1.12
name: wrong-main
version: 0.0.0build-type: Simple
executablewrong-mainmain-is: Foo.hs
other-modules:
Bar
Paths_wrong_main
hs-source-dirs:
./
build-depends:
base
default-language: Haskell2010
is accepted, while Bar.hs contains module Main. there aren't module Bar.
And I don't have a good solution to this problem.
I thought long ago, that if GHC accepted arguments something like Bar:path/to/SomeFile.hs, then it would solve this issue; and also make it possible to turn automatic module discovery in GHC (which would allow components to share hs-source-dirs). In this case GHC should complain if module name and given module paths don't agree.
Then we allow different syntax for main-is, matching the above main-is: Foo:Foo.hs, and treat old variants, i.e. main-is: Foo.hs as if they were main-is: Main:Foo.hs.
TL;DR, the core problem is that Cabal and GHC have to no way to communicate module <-> path mapping; and Cabal has to "reverse-engineer" what GHC is doing, instead of being explicit, and just telling GHC where to look for the sources.
I.e. I think this is GHC design issue. Parsing Haskell files to figure out module names is not something Cabal should even consider doing. (For example there could be custom literate preprocessor, or even just complicated CPP)
If the module in
main-is
has a name and there is another module that has no explicit name (nomodule
header), then the other module is picked as main module.Bar.hs
Foo.hs
wrong-main.cabal
Packaged reproducer: wrong-main.tgz
Analysis: It seems Cabal calls GHC this way:
The correct result can be obtained by adding
-main-is Foo
:I suppose the difficulty is to extract the module name
Foo
fromFoo.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:
main-is
field (source file) does not alter GHC's-main-is
option (module and function name) commercialhaskell/stack#6695The text was updated successfully, but these errors were encountered: