Fix incorrect import warnings when methods with identical names are imported
authorÖmer Sinan Ağacan <omeragacan@gmail.com>
Tue, 13 Oct 2015 05:47:28 +0000 (00:47 -0500)
committerAustin Seipp <austin@well-typed.com>
Tue, 13 Oct 2015 05:47:35 +0000 (00:47 -0500)
commit1818b48e420fd0f689105da76721895aadee7fd6
tree686d13d1cc2264dc734b845d811870fb9907ff40
parentd2f9972a35ce05ceb8a78893e433ef1df06f73ef
Fix incorrect import warnings when methods with identical names are imported

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
compiler/rename/RnNames.hs
testsuite/tests/warnings/should_compile/T10890/A.hs [new file with mode: 0644]
testsuite/tests/warnings/should_compile/T10890/B.hs [new file with mode: 0644]
testsuite/tests/warnings/should_compile/T10890/Base.hs [new file with mode: 0644]
testsuite/tests/warnings/should_compile/T10890/Extends.hs [new file with mode: 0644]
testsuite/tests/warnings/should_compile/T10890/Makefile [new file with mode: 0644]
testsuite/tests/warnings/should_compile/T10890/T10890.hs [new file with mode: 0644]
testsuite/tests/warnings/should_compile/T10890/T10890_1.hs [new file with mode: 0644]
testsuite/tests/warnings/should_compile/T10890/all.T [new file with mode: 0644]