[GHC] #12067: warn-unused-imports does not detect coersions

GHC ghc-devs at haskell.org
Sun May 15 18:54:41 UTC 2016


#12067: warn-unused-imports does not detect coersions
-------------------------------------+-------------------------------------
           Reporter:  crockeea       |             Owner:
               Type:  bug            |            Status:  new
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  7.10.3
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  Incorrect
  Unknown/Multiple                   |  warning at compile-time
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 When using `coerce`, GHC can erroneously warn that imports are
 unnecessary. For example:

 Foo.hs
 {{{
 module Foo (MT(..), M) where

 import Control.Monad.Identity

 newtype MT m b = MT (m b)
 type M b = MT Identity b
 }}}

 Main.hs
 {{{
 import Control.Monad.Identity
 import Data.Coerce
 import Foo

 foo :: M [a] -> MT [] a
 foo = coerce
 }}}

 GHC (with `-fwarn-unused-imports`) warns
 {{{
 Main.hs:1:1: Warning:
     The import of ‘Control.Monad.Identity’ is redundant
       except perhaps to import instances from ‘Control.Monad.Identity’
     To import instances alone, use: import Control.Monad.Identity()
 }}}

 But this is incorrect: we need the constructor `Identity` to be in scope
 in order for the coercion to succeed. Thus the import is not redundant,
 nor is it needed to import instances. In particular, the two implied
 suggestions

  1. remove the import altogether
  2. change the import to `import Control.Monad.Identity`

 both (correctly) result in compile errors.

 At a minimum, the warning message should be updated to include this
 possibility, but it would be even better if GHC could detect this and not
 throw a warning at all.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/12067>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list