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. 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, which also replaced an errant use of `tyConTyVars` with type variables from each data constructor.) Fixes #22167.
Showing
- compiler/GHC/Tc/Deriv/Functor.hs 30 additions, 2 deletionscompiler/GHC/Tc/Deriv/Functor.hs
- compiler/GHC/Tc/Deriv/Generics.hs 18 additions, 3 deletionscompiler/GHC/Tc/Deriv/Generics.hs
- compiler/GHC/Tc/Deriv/Infer.hs 34 additions, 17 deletionscompiler/GHC/Tc/Deriv/Infer.hs
- testsuite/tests/deriving/should_compile/T22167.hs 24 additions, 0 deletionstestsuite/tests/deriving/should_compile/T22167.hs
- testsuite/tests/deriving/should_compile/all.T 1 addition, 0 deletionstestsuite/tests/deriving/should_compile/all.T
Loading
Please register or sign in to comment