Skip to content

Redundant import warning is sometimes not correct

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.
Trac metadata
Trac field Value
Version 6.12.1
Type Bug
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information