Adjust reporting of unused tyvars in data FamInsts
This commit adjusts the validity checking of data family instances to improve the reporting of unused type variables. See Note [Out of scope tvs in data family instances] in GHC.Tc.Validity. The problem was that, in a situation such as data family D :: Type data instance forall (d :: Type). D = MkD the RHS passed to 'checkFamPatBinders' would be the TyCon app R:D d which mentions the type variable 'd' quantified in the user-written forall. Thus, when computing the set of unused type variables in the RHS of the data family instance, we would find that 'd' is used, and report a strange error message that would say that 'd' is not bound on the LHS. To fix this, we special-case the data-family instance case, manually extracting all the type variables that appear in the arguments of all the data constructores of the data family instance. Fixes #23778
Showing
- compiler/GHC/Tc/Validity.hs 72 additions, 3 deletionscompiler/GHC/Tc/Validity.hs
- testsuite/tests/indexed-types/should_fail/ExplicitForAllFams4b.stderr 9 additions, 9 deletions...sts/indexed-types/should_fail/ExplicitForAllFams4b.stderr
- testsuite/tests/typecheck/should_fail/T23734.hs 17 additions, 0 deletionstestsuite/tests/typecheck/should_fail/T23734.hs
- testsuite/tests/typecheck/should_fail/T23778.hs 7 additions, 0 deletionstestsuite/tests/typecheck/should_fail/T23778.hs
- testsuite/tests/typecheck/should_fail/T23778.stderr 5 additions, 0 deletionstestsuite/tests/typecheck/should_fail/T23778.stderr
- testsuite/tests/typecheck/should_fail/all.T 1 addition, 0 deletionstestsuite/tests/typecheck/should_fail/all.T
Loading
Please register or sign in to comment