id,summary,reporter,owner,description,type,status,priority,milestone,component,version,resolution,keywords,cc,os,architecture,failure,difficulty,testcase,blockedby,blocking,related
3992,Redundant import warning is sometimes not correct,basvandijk,,"When working on my usb-safe library I just discovered a warning message that doesn't seem right. 

Suppose you have the following three modules: 

(I tried to trim down the problem so I simplified and changed most types, classes, instances and functions. They don't matter for this discussion. The only things that matter are the names that are in- and exported)

{{{Resource.hs:}}}
{{{
{-# LANGUAGE TypeFamilies #-}

module Resource ( Resource, Handle, open, close ) where

class Resource r where
    data Handle r :: *

    open  :: r -> IO (Handle r)
    close :: Handle r -> IO ()
}}}

{{{Region.hs:}}}
{{{
module Region ( open, run ) where

open :: Char -> String
open = (:[])

run :: Maybe a -> Bool
run = maybe False (const True)
}}}

{{{USB.hs:}}}
{{{
{-# LANGUAGE TypeFamilies #-}

module USB ( Device(..)
           , claim
           , foo
           , module Region
           ) where

import Resource ( Resource, Handle, open, close )
import Region
import qualified Region as QualifiedRegion ( open )

newtype Device = Device {unDevice :: Int}

instance Resource Device where
    data Handle Device = DeviceHandle Int

    open  = return . DeviceHandle . unDevice
    close = const $ return ()

claim :: Char -> String
claim = QualifiedRegion.open

foo :: Maybe a -> Bool
foo = run
}}}

When I load USB.hs in ghci with all warnings on I get the following warning:

{{{$ ghci -Wall USB.hs}}}
{{{
USB.hs:9:0:
    Warning: The import of `Resource.open'
             from module `Resource' is redundant
Ok, modules loaded: USB, Region, Resource.
}}}

Why is {{{Resource.open}}} redundant while I use it in an instance declaration?

If the warning is correct so {{{Resource.open}}} is redundant we can just as well remove the import. However when I remove it I get the following error:

{{{
USB.hs:18:4: `open' is not a (visible) method of class `Resource'
Failed, modules loaded: Region, Resource.
}}}",bug,closed,normal,,Compiler,6.12.1,fixed,,,Unknown/Multiple,Unknown/Multiple,Incorrect warning at compile-time,,,,,
