Inconsistent warnings for unused binders in type and instance declarations
Consider compiling this with -Wunused-matches
:
class C a where
op :: a -> a
instance C (Maybe a) where
op x = x
We get no warnings, even though a
is patently unused.
But suppose we add an associated type
class C a where
type T a
op :: a -> a
instance C (Maybe a) where
type T (Maybe a) = Int -- Warning on this line
op x = x
Now we get a warning for an unused binding for a
on the type instance
.
Edward complained about this inconsistent behaviour in this email thread.
My thoughts:
- Currently GHC does not warn about type variables bound in the instance head but unused in the
where
part. Fixing that might be a good idea, but would be a new feature. - However, given that we don't warn about them, we should definitely not warn about instance type variables being unused in an associated type. But we could warn about ones specific to the associated type itself. Eg
class C2 a where
type T2 a b
instance C2 (Maybe a) where
type T2 (Maybe a) x = Int -- Line XXX
Here, on line
XXX
, we might reasonably warn about the unusedx
, but not about the unuseda
.
Trac metadata
Trac field | Value |
---|---|
Version | 7.10.3 |
Type | Bug |
TypeOfFailure | OtherFailure |
Priority | normal |
Resolution | Unresolved |
Component | Compiler |
Test case | |
Differential revisions | |
BlockedBy | |
Related | |
Blocking | |
CC | ekmett |
Operating system | |
Architecture |