1

I have following problem with ghc-mod which prevents me from using ide for some files in a yesod app project.

I install template app as follows:

/tmp$ stack new demo yesod-sqlite && cd demo
/tmp/demo$ stack setup && stack build && stack install ghc-mod

Which yields following stack.yaml (commented lines removed):

resolver: lts-5.6
packages:
- '.'
extra-deps: []
flags: {}
extra-package-dbs: []

And this is a demo.cabal: http://pastebin.com/i4n1TR6W.

Then, running stack exec -- ghc-mod check app/main.hs does not produce errors, but stack exec -- ghc-mod check app/devel.hs has this to say:

app/devel.hs:2:1:Failed to load interface for ‘Application’It is a member of the hidden package ‘demo-0.0.0’.Perhaps you need to add ‘demo’ to the build-depends in your .cabal file.

So the ghc-mod somehow thinks this package is itself hidden? But any other place where project's files are imported by another checks fine, and the application builds and works successfully. The only specifics about this file is using PackageImports language extension:

{-# LANGUAGE PackageImports #-}
import "demo" Application (develMain)

I tried googling the error message but it seems to only come up with regard to external packages and not the one being debugged.

Cthulhu
  • 1,379
  • 1
  • 13
  • 25
  • What is the contents of your `.cabal` file? – Zeta Mar 12 '16 at 18:42
  • @Zeta Here it is: http://pastebin.com/i4n1TR6W. – Cthulhu Mar 12 '16 at 18:52
  • `devel.hs` isn't referenced by either library or any other target. Could you add `app/devel.hs` as `extra-source-files:`? I think that ghc-mod simply does not recognize its relation to your package. – Zeta Mar 12 '16 at 18:57
  • @Zeta I thinks it's used by `yesod` binary (one from `yesod-bin` package), `strings ... | grep devel.hs` finds it there. – Cthulhu Mar 12 '16 at 19:02
  • @Zeta adding it to `extra-source-files` doesn't help. Also, if I remove the package name from the import statement there, the check is fine (but the build is not anymore, must be `Application` from some other package gets imported. – Cthulhu Mar 12 '16 at 19:13

1 Answers1

1

These two files devel.hs and DevelMain.hs are quite special: they are marked as a module of demo in .cabal but they are importing demo as a compiled package, i.e. recursive dependency.

They are not exposed from library demo nor imported anywhere else so won't get compiled when you run stack build, but when you run ghc-mod check on them, they are interpreted in the context of the current project, therefore the recursive dependency will be an issue.


The only purpose of these two otherwise meaningless files is to debug your yesod website in ghci, as the comment in DevelMain.hs stated:

-- | Running your app inside GHCi.
--
-- To start up GHCi for usage with Yesod, first make sure you are in dev mode:
--
-- > cabal configure -fdev
--
-- Note that @yesod devel@ automatically sets the dev flag.
-- Now launch the repl:
--
-- > cabal repl --ghc-options="-O0 -fobject-code"
--
-- To start your app, run:
--
-- > :l DevelMain
-- > DevelMain.update
--
-- You can also call @DevelMain.shutdown@ to stop the app
--
-- You will need to add the foreign-store package to your .cabal file.
-- It is very light-weight.
--
-- If you don't use cabal repl, you will need
-- to run the following in GHCi or to add it to
-- your .ghci file.
--
-- :set -DDEVELOPMENT
--
-- There is more information about this approach,
-- on the wiki: https://github.com/yesodweb/yesod/wiki/ghci

cabal repl and stack ghci will compile the project beforehand so these two files won't cause any error there.

zakyggaps
  • 3,070
  • 2
  • 15
  • 25
  • 1
    Okay, so I guess it cant be helped (but only these two files are affected). On the side note, they (at least `devel.hs`) are also used when one runs `yesod devel`. – Cthulhu Mar 14 '16 at 07:45