Overzealous unused-top-binds
The following example produces three warnings:
module Foo () where
type A = Int
type B = A
foo :: IO ()
foo = print (bar 3 :: B)
bar :: a -> a
bar = id
ghci Foo -Wall produces
GHCi, version 8.0.1.20161117: http://www.haskell.org/ghc/ :? for help
[1 of 1] Compiling Foo ( Foo.hs, interpreted )
Foo.hs:5:1: warning: [-Wunused-top-binds]
Defined but not used: type constructor or class ‘B’
Foo.hs:8:1: warning: [-Wunused-top-binds]
Defined but not used: ‘foo’
Foo.hs:11:1: warning: [-Wunused-top-binds]
Defined but not used: ‘bar’
Ok, modules loaded: Foo.
The three errors reported are inconsistent because GHC reports that B is unused, but somehow feels that A *is* used.
It seems to me that two possibilities could work:
- GHC reports 1 error:
GHC should only report that foo is unused, since A is used in B, B is used in foo, and bar is used in foo. This seems like the best approach to me.
- GHC reports 4 errors:
One might choose to apply the definition of "unused" transitively so that, since foo is unused, everything used in foo is considered unused (unless "used" elsewhere). In this case, A should also be reported as unused, but it currently isn't. This definition would be exceedingly useful for removing dead code, but it also produces very noisy output when there is a lot of dead code.
Trac metadata
| Trac field | Value |
|---|---|
| Version | 8.0.2-rc1 |
| Type | Bug |
| TypeOfFailure | OtherFailure |
| Priority | normal |
| Resolution | Unresolved |
| Component | Compiler |
| Test case | |
| Differential revisions | |
| BlockedBy | |
| Related | |
| Blocking | |
| CC | |
| Operating system | |
| Architecture |