DeriveFunctor: Check for last type variables using dataConUnivTyVars
Previously, derived instances of Functor
(as well as the related classes
Foldable
, Traversable
, and Generic1
) would determine which constraints to
infer by checking for fields that contain the last type variable. The problem
was that this last type variable was taken from tyConTyVars
. For GADTs, the
type variables in each data constructor are not the same type variables as
in tyConTyVars
, leading to #22167 (closed).
This fixes the issue by instead checking for the last type variable using
dataConUnivTyVars
. (This is very similar in spirit to the fix for #21185 (closed),
which also replaced an errant use of tyConTyVars
with type variables from
each data constructor.)
Fixes #22167 (closed).