Skip to content

Regression in 9.0.1: -Werror=unused-packages suppresses real compilation error

Summary

Turning on -Werror=unused-packages in the cabal file causes actual error to be dropped.

Steps to reproduce

BootNoHeader.zip

cabal build the following scenario:

  • BootNoHeader.cabal
cabal-version:      2.4
name:               BootNoHeader
version:            0.1.0.0

executable BootNoHeader
    main-is:          Main.hs
    other-modules:    Foo
    build-depends:    base
    hs-source-dirs:   .
    default-language: Haskell2010

    ghc-options:      -Werror=unused-packages
  • Main.hs
module Main where

import {-# SOURCE #-} Foo

main = putStrLn "Hello, world!"
  • Foo.hs
module Foo where

a :: Int
a = 5
  • Foo.hs-boot
a :: Int

Note: This boot file lacks the correct module header, which is an error.

Expected behavior

I'd like to see the error (works if -Werror=unused-packages is not given).

Foo.hs-boot:1:1: error:
    File name does not match module name:
    Saw: ‘Main’
    Expected: ‘Foo’
  |
1 | a :: Int
  | ^

This is the behavior with GHC <= 8.10

Actual behavior

This faulty error is printed:

<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:
      - base-4.15.0.0

Environment

  • GHC version used: 9.0.1, 9.2.1-rc1
  • Cabal versions tried: 3.2, 3.5
Edited by Andreas Abel
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information