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

Abierto
#6,695 13 comentarios 0 reacciones 1 asignado Ver en GitHub

@mpilgrem ya está trabajando en esto.

Desde el 15/3/2025.

Evaluación

Este issue todavía no se ha evaluado.

Descripción

component: build component: Cabal library resolution: upstream issue type: question

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:

Lenguaje dominante
Haskell
Estrellas
4.1k
Forks
857
Merge medio
17 h 32 min
PR fusionados (30 d)
5

Preparar el entorno

Abrir en Codespaces

Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de commercialhaskell/stack

Todos los issues de commercialhaskell/stack

Issues similares

Más issues de Haskell

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.