• Ömer Sinan Ağacan's avatar
    Fix incorrect import warnings when methods with identical names are imported · 1818b48e
    Ömer Sinan Ağacan authored
    Currently, GHC's warning generation code is assuming that a name (`RdrName`)
    can be imported at most once. This is a correct assumption, because 1) it's OK
    to import same names as long as we don't use any of them 2) when we use one of
    them, GHC generates an error because it doesn't disambiguate it automatically.
    
    But apparently the story is different with typeclass methods. If I import two
    methods with same names, it's OK to use them in typeclass instance
    declarations, because the context specifies which one to use. For example, this
    is OK (where modules A and B define typeclasses A and B, both with a function
    has),
    
        import A
        import B
    
        data Blah = Blah
    
        instance A Blah where
          has = Blah
    
        instance B Blah where
          has = Blah
    
    But GHC's warning generator is not taking this into account, and so if I change
    import list of this program to:
    
        import A (A (has))
        import B (B (has))
    
    GHC is printing these warnings:
    
        Main.hs:5:1: Warning:
            The import of ‘A.has’ from module ‘A’ is redundant
    
        Main.hs:6:1: Warning:
            The import of ‘B.has’ from module ‘B’ is redundant
    
    Why? Because warning generation code is _silently_ ignoring multiple symbols
    with same names.
    
    With this patch, GHC takes this into account. If there's only one name, then
    this patch reduces to the previous version, that is, it works exactly the same
    as current GHC (thanks goes to @quchen for realizing this).
    
    Reviewed By: austin
    
    Differential Revision: https://phabricator.haskell.org/D1257
    
    GHC Trac Issues: #10890
    1818b48e
Extends.hs 54 Bytes