Haskell-ide-engine: Cannot have two "Main" modules open at the same time

Created on 4 Jun 2018  Â·  10Comments  Â·  Source: haskell/haskell-ide-engine

e.g., working on hie, if app/MainHie.hs and test/Functional.hs are both loaded, we get

Got error while processing diagnostics: <no location info>: error:
    module ‘haskell-ide-engine-0.2.0.0-7HZrGfRRjONEXbBFqqpRFd:Main’ is defined in multiple files:
         /tmp/ghc-mod17562/MainHie17561-6.hs
         /tmp/ghc-mod17564/RealFunctional17561-5.hs

Note: I think is because we put all the mapped files into the targets list in ghc-mod when loading.

Most helpful comment

Any update on this? Still have this issue in VS Code with the same setup as @ahpearce.

All 10 comments

The problem is with the mappedStrs all being added to the list of targets to be loaded here: https://github.com/alanz/ghc-mod/blob/ghc-8.4-hie/core/GhcMod/Target.hs#L217

    mappedStrs <- getMMappedFilePaths
    let targetStrs = mappedStrs ++ map moduleNameString mns ++ cfns

We need to filter out any know main modules from that list, by inspecting the cabal component graph, and marking any successfully loaded main modules.

@alanz
I am still getting this issue in VSCode

Got error while processing diagnostics: <no location info>: error: module ‘main:Main’ is defined in multiple files: /private/var/folders/9v/5p73rgqn65ddfzcvrjf2nj8c0000gn/T/ghc-mod560/problem5559-0.hs /private/var/folders/9v/5p73rgqn65ddfzcvrjf2nj8c0000gn/T/ghc-mod561/problem6559-3.hs

I've got a project setup like:

drwxr-xr-x   3 adam  staff   96 Jun 27 16:18 problem1
drwxr-xr-x   3 adam  staff   96 Jun 27 16:18 problem2
drwxr-xr-x   3 adam  staff   96 Jun 27 16:19 problem3
drwxr-xr-x   3 adam  staff   96 Jun 27 16:19 problem4
drwxr-xr-x   6 adam  staff  192 Jun 27 18:23 problem5
drwxr-xr-x   3 adam  staff   96 Jun 27 18:25 problem6

Where each directory has a .hs file specifying a main.

> hie --version
Version 0.2.0.0, Git revision 3370c8a0a8808e03c1f6354bcecddd80593cf546 (1539 commits) x86_64 ghc-8.4.3

Should the above version have this update included or am I missing something?

@ahpearce And you do not have any cabal or stack files?

@alanz
Which files would be helpful?
../haskell-ide-engine/haskell-ide-engine.cabal : https://gist.github.com/ahpearce/faa5500e5b621108ea900333a4dd0da2

../haskell-ide-engine/stack.yaml : https://gist.github.com/ahpearce/abc2846b51c9d73b4fdf131de347840d

I have the same error with same setup as @ahpearce - no cabal or stack project, just number of .hs files, each .hs has Main module.

I'm on Windows 10, if that matters.

As a workaround, I created a simple project stack new <project-name> new-template
and put each .hs into its own directory and put this into package.yaml:

executables:
  1_money_change-exe:
    main:                Main.hs
    source-dirs:         src/1_money_change
    ghc-options:
    - -Wall
    - -Werror
    - -O2

  2_maximum_value_of_the_loot-exe:
    main:                Main.hs
    source-dirs:         src/2_maximum_value_of_the_loot
    ghc-options:
    - -Wall
    - -Werror
    - -O2

  ...

With this setup there is no error about multiple Main modules.

Still, plain GHC project would be much more convenient for my purposes. It'd be awesome if that error went away.

@Eoksni for reference I believe this is the same issue as https://github.com/haskell/haskell-ide-engine/issues/770

Any update on this? Still have this issue in VS Code with the same setup as @ahpearce.

hello, anyone working on this?

Assuming you have a correct stack or cab project, e.g. Cabal build or stack build succeed, this problem does not occur on current master

Was this page helpful?
0 / 5 - 0 ratings

Related issues

xgrommx picture xgrommx  Â·  4Comments

awave1 picture awave1  Â·  4Comments

alanz picture alanz  Â·  3Comments

fendor picture fendor  Â·  4Comments

nponeccop picture nponeccop  Â·  4Comments