hlint icon indicating copy to clipboard operation
hlint copied to clipboard

"Use fewer imports" behaviour does not seem to take into account CPP version bounds.

Open Kleidukos opened this issue 5 years ago • 3 comments

HLint seems to trip on that piece of code:

import Data.Bits (shiftL, shiftR, (.|.), (.&.))

#if MIN_VERSION_base(4,7,0)
import Data.Bits (finiteBitSize)
#else
import Data.Bits (Bits, bitSize)

finiteBitSize :: (Bits a) => a -> Int
finiteBitSize = bitSize
#endif
libraries/base/GHC/Windows.hs:77:1-47: Warning: Use fewer imports
Found:
  import Data.Bits ( shiftL, shiftR, (.|.), (.&.) )
  import Data.Bits ( Bits, bitSize )
Perhaps:
  import Data.Bits ( shiftL, shiftR, (.|.), (.&.), Bits, bitSize )

Kleidukos avatar Sep 19 '20 09:09 Kleidukos

Nothing in HLint takes account CPP at all, unfortunately. It just can't see the CPP is even there. With a little hand holding you can encourage it to take one branch or another, but that's the best you can do, unfortunately.

Maybe it's worth detecting CPP in a module, and in that case, disabling the warnings that are most likely to go wrong with CPP - use fewer imports being one.

ndmitchell avatar Sep 19 '20 10:09 ndmitchell

I am going to put those modules in the exclude list for that hint for the moment. Thank you Neil. :)

Kleidukos avatar Sep 19 '20 10:09 Kleidukos

Nothing in HLint takes account CPP at all, unfortunately.

Good to know, thanks @ndmitchell. I put this to the test with hlint-3.8 and HLint is not warning when {-# LANGUAGE CPP #-} is an unused language pragma.

philderbeast avatar Jan 06 '25 15:01 philderbeast