Use addUsedDataCons more judiciously in TcDeriv (#17324)
If you derive an instance like this:
deriving <...> instance Foo C
And the data constructors for C
aren't in scope, then
doDerivInstErrorChecks1
throws an error. Moreover, it will
only throw an error if <...>
is either stock
or newtype
.
This is because the code that the anyclass
or via
strategies
would generate would not require the use of the data constructors
for C
.
However, doDerivInstErrorChecks1
has another purpose. If you
write this:
import M (C(MkC1, ..., MkCn))
deriving <...> instance Foo C
Then doDerivInstErrorChecks1
will call addUsedDataCons
on
MkC1
through MkCn
to ensure that -Wunused-imports
does not
complain about them. However, doDerivInstErrorChecks1
was doing
this for every deriving strategy, which mean that if <...>
were
anyclass
or via
, then the warning about MkC1
through MkCn
being unused would be suppressed!
The fix is simple enough: only call addUsedDataCons
when the
strategy is stock
or newtype
, just like the other code paths
in doDerivInstErrorChecks1
.
Fixes #17324 (closed).