Skip to content

`-Wunused-packages` overreports with alternative Preludes

Summary

Using an alternative Prelude (in my case, Relude) through mixins will cause -Wunused-packages to report that a package is unused when it is actually used. I suspect this might be related to #18563, which is also related to mixins.

Steps to reproduce

  1. Clone https://github.com/elldritch/cabal-unused-packages-mixin-repro and make sure you're running GHC 9.4.7.
  2. Run cabal build.

You should see this error message:

$ cabal build
Build profile: -w ghc-9.4.7 -O1
In order, the following will be built (use -v for more details):
 - cabal-unused-packages-mixin-repro-0.1.0.0 (lib) (file src/Example.hs changed)
Preprocessing library for cabal-unused-packages-mixin-repro-0.1.0.0..
Building library for cabal-unused-packages-mixin-repro-0.1.0.0..

<no location info>: error: [-Wunused-packages, -Werror=unused-packages]
    The following packages were specified via -package or -package-id flags,
    but were not needed for compilation:
      - relude-1.2.1.0 (exposed by flag -package-id relude-1.2.1.0-ea787ea216b250f63edab15a196f92bee0e612410323d35bd7a6caf35e8a006b)
Error: cabal: Failed to build cabal-unused-packages-mixin-repro-0.1.0.0.

Expected behavior

This warning should not be triggered, since Relude is being imported as the implicit Prelude.

Environment

  • GHC version used: 9.4.7

Optional:

  • Operating System: Arch Linux
  • System Architecture: x86_64
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information