Skip to content
This repository was archived by the owner on Oct 7, 2020. It is now read-only.

Cannot have two "Main" modules open at the same time #620

Closed
alanz opened this issue Jun 4, 2018 · 10 comments
Closed

Cannot have two "Main" modules open at the same time #620

alanz opened this issue Jun 4, 2018 · 10 comments
Milestone

Comments

@alanz
Copy link
Collaborator

alanz commented Jun 4, 2018

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.

@alanz
Copy link
Collaborator Author

alanz commented Jun 18, 2018

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
Copy link
Collaborator Author

alanz commented Jun 19, 2018

As pointed out by @wz1000 on IRC, we should be able to reinstate

wz1000/ghc-mod@43606f3
wz1000/ghc-mod@1279f61

@adamhp
Copy link

adamhp commented Jun 30, 2018

@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?

@alanz
Copy link
Collaborator Author

alanz commented Jul 2, 2018

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

@adamhp
Copy link

adamhp commented Jul 3, 2018

@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

@Eoksni
Copy link

Eoksni commented Aug 25, 2018

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.

@lukel97
Copy link
Collaborator

lukel97 commented Aug 26, 2018

@Eoksni for reference I believe this is the same issue as #770

@alanz alanz added this to the prehistory milestone Feb 2, 2019
@xhliu
Copy link

xhliu commented Aug 26, 2019

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

@xhliu
Copy link

xhliu commented Dec 24, 2019

hello, anyone working on this?

@fendor
Copy link
Collaborator

fendor commented Dec 24, 2019

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants