Reject instance with non-class head in renamer
This commit modifies rnClsInstDecl so that, when renaming, we reject a class instance declaration in which the head is not a class. Before this change, it would get rejected in the type-checker, but that meant that the renamer could emit unhelpful error messages, e.g.: data Foo m a instance Foo m where fmap _ x = case x of would rather unhelpfully say: ‘fmap’ is not a (visible) method of class ‘Foo’ when of course 'Foo' is not even a class. We now reject the above program with the following error message: Illegal instance for data type ‘Foo’. Instance heads must be of the form C ty_1 ... ty_n where ‘C’ is a class. Fixes #22688
Showing
- compiler/GHC/Rename/Module.hs 42 additions, 17 deletionscompiler/GHC/Rename/Module.hs
- compiler/GHC/Tc/Errors/Ppr.hs 8 additions, 8 deletionscompiler/GHC/Tc/Errors/Ppr.hs
- compiler/GHC/Tc/Errors/Types.hs 10 additions, 5 deletionscompiler/GHC/Tc/Errors/Types.hs
- compiler/GHC/Tc/Gen/HsType.hs 4 additions, 2 deletionscompiler/GHC/Tc/Gen/HsType.hs
- compiler/GHC/Tc/Validity.hs 4 additions, 3 deletionscompiler/GHC/Tc/Validity.hs
- compiler/GHC/Types/Error/Codes.hs 2 additions, 2 deletionscompiler/GHC/Types/Error/Codes.hs
- testsuite/tests/rename/should_fail/T22688.hs 6 additions, 0 deletionstestsuite/tests/rename/should_fail/T22688.hs
- testsuite/tests/rename/should_fail/T22688.stderr 7 additions, 0 deletionstestsuite/tests/rename/should_fail/T22688.stderr
- testsuite/tests/rename/should_fail/all.T 1 addition, 0 deletionstestsuite/tests/rename/should_fail/all.T
Loading
Please register or sign in to comment