Skip to content

ghc-pkg and ghc do not agree about package with internal libraries

Initially I reported this to Cabal (https://github.com/haskell/cabal/issues/5857), but I think this is actually a GHC bug.

Repro here: https://github.com/michaelpj/cabal-bug-package-db

In particular, you can run the following.

$ cabal build                                                                                                                                  
$ ghc-pkg field test exposed -f dist/package.conf.inplace
exposed: True
$ ghc-pkg find-module Test -f dist/package.conf.inplace
dist/package.conf.inplace
    test-0.1.0.0
$ ghc -package-db dist/package.conf.inplace Use.hs
[1 of 1] Compiling Use              ( Use.hs, Use.o )                                                                                                                                      
                                                                                                                                                                                           
Use.hs:3:1: error:                                                                                                                                                                         
    Could not load module ‘Test’                                                                                                                                                           
    It is a member of the hidden package ‘test-0.1.0.0’.                                                                                                                                   
    You can run ‘:set -package test’ to expose it.                                                                                                                                         
    (Note: this unloads all the modules in the current scope.)                                                                                                                             
    Use -v to see a list of the files searched for.                                                                                                                                        
  |                                                                                                                                                                                        
3 | import Test                                                                                                                                                                            
  | ^^^^^^^^^^^     
$ ghc -package-db dist/package.conf.inplace -package test Use.hs
[1 of 1] Compiling Use              ( Use.hs, Use.o )

That is:

  • ghc-pkg thinks the package is present, exposed, and contains the module in question.
  • ghc thinks the package is hidden, and will accept it when specified with -package.

If you comment out the internal library this does not happen, but regardless it seems bad that there's a disagreement between ghc-pkg and ghc.

I've also observed (although I don't have a small reproduction for this) a similar case where ghc does not even think the module is hidden, but again will accept it with -package.

Trac metadata
Trac field Value
Version 8.6.3
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component ghc-pkg
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information