carlohamalainen / ghc-imported-from

For a given Haskell source file, determine where a symbol is imported from
BSD 3-Clause "New" or "Revised" License
26 stars 2 forks source link

Choose best result from parseName instead of arbitrarily taking the first #2

Closed carlohamalainen closed 10 years ago

carlohamalainen commented 10 years ago

The symbol "when" is exported by these packages:

Control.Monad.Identity, Control.Monad.Reader, Control.Monad.Error,
Control.Monad.List, Control.Monad.RWS.Lazy, Control.Monad.RWS,
Control.Monad.RWS.Strict, Control.Monad.State.Lazy, Control.Monad.State,
Control.Monad.State.Strict, Control.Monad.Writer.Lazy, Control.Monad.Writer,
Control.Monad.Writer.Strict, Control.Monad.Cont

so if our program has these imports

import Control.Monad ( forM_, liftM, filterM, when, unless )
import Control.Monad.Identity
import Control.Monad.Reader
import Control.Monad.Trans.Writer.Lazy

then lookupSymbol will return

[Control.Monad.Reader, Control.Monad.Identity, Control.Monad]

because parseNames has no local type information to differentiate between the different versions of when.

Possible fix: check for a selective import of the specified symbol and take preference if a match appears in the output of lookupSymbol.

carlohamalainen commented 10 years ago
commit 09cd6bc0e0e4fda4f61ba2db99563378065fc3fd
Author: Carlo Hamalainen <carlo.hamalainen@gmail.com>
Date:   Sun Jan 5 20:40:32 2014 +0100

    Better guess of imported module when selective imports are used.