Skip to content

StandaloneDeriving suppresses unused data constructor imports

This program does not emit any warnings:

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# OPTIONS_GHC -Wall #-}
module Bug where

import Data.Monoid (Sum(Sum))

class C a
deriving anyclass instance C (Sum a)

But this one does:

{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DerivingStrategies #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# OPTIONS_GHC -Wall #-}
module Bug where

import Data.Monoid (Sum(Sum))

class C a
instance C (Sum a)
$ /opt/ghc/8.8.1/bin/ghci Bug.hs
GHCi, version 8.8.1: https://www.haskell.org/ghc/  :? for help
Loaded GHCi configuration from /home/rgscott/.ghci
[1 of 1] Compiling Bug              ( Bug.hs, interpreted )

Bug.hs:7:1: warning: [-Wunused-imports]
    The import of ‘Sum’ from module ‘Data.Monoid’ is redundant
  |
7 | import Data.Monoid (Sum(Sum))
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

This is strange, since DeriveAnyClass should produce the exact same code as an empty instance does. I would expect both programs to emit warnings.

Patch incoming.

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information