Skip to content

Cabal's main-is field (source file) does not alter GHC's -main-is option (module and function name) #6695

Open
@andreasabel

Description

@andreasabel

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
$ stack run
...                                                                                                       
I am the shady main...

Packaged reproducer: wrong-main.tgz

The wrong result can be reproduced with this vanilla GHC call:

ghc --make Foo.hs Bar.hs

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.

This issue is shared with cabal:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions