Skip to content

`-Wunused-imports` gets confused by `NoFieldSelectors`

Summary

If you use -Wunused-imports together with NoFieldSelectors then you can get false positives.

Steps to reproduce

{-# OPTIONS_GHC -Werror=unused-imports #-}
module Foo (main) where

import Lib (foo)

main :: IO ()
main = print foo
{-# LANGUAGE NoFieldSelectors #-}
module Lib where

foo :: Int
foo = 23

data Foo = Foo {
  foo :: Int
}
$ runhaskell Main.hs

Main.hs:4:13: error: [-Wunused-imports, Werror=unused-imports]
    The import of ‘Foo(foo)’ from module ‘Lib’ is redundant
  |
4 | import Lib (foo)
  |             ^^^

Expected behavior

$ runhaskell Main.hs
23

Environment

  • GHC version used: 9.6.1 / 9.6.2
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information