Reject nested foralls/contexts in instance types more consistently
GHC is very wishy-washy about rejecting instance declarations with nested `forall`s or contexts that are surrounded by outermost parentheses. This can even lead to some strange interactions with `ScopedTypeVariables`, as demonstrated in #18240. This patch makes GHC more consistently reject instance types with nested `forall`s/contexts so as to prevent these strange interactions. On the implementation side, this patch tweaks `splitLHsInstDeclTy` and `getLHsInstDeclHead` to not look through parentheses, which can be semantically significant. I've added a `Note [No nested foralls or contexts in instance types]` in `GHC.Hs.Type` to explain why. This also introduces a `no_nested_foralls_contexts_err` function in `GHC.Rename.HsType` to catch nested `forall`s/contexts in instance types. This function is now used in `rnClsInstDecl` (for ordinary instance declarations) and `rnSrcDerivDecl` (for standalone `deriving` declarations), the latter of which fixes #18271. On the documentation side, this adds a new "Formal syntax for instance declaration types" section to the GHC User's Guide that presents a BNF-style grammar for what is and isn't allowed in instance types. Fixes #18240. Fixes #18271.
Showing
- compiler/GHC/Hs/Type.hs 169 additions, 48 deletionscompiler/GHC/Hs/Type.hs
- compiler/GHC/Rename/Module.hs 111 additions, 44 deletionscompiler/GHC/Rename/Module.hs
- docs/users_guide/8.12.1-notes.rst 16 additions, 0 deletionsdocs/users_guide/8.12.1-notes.rst
- docs/users_guide/exts/explicit_forall.rst 5 additions, 0 deletionsdocs/users_guide/exts/explicit_forall.rst
- docs/users_guide/exts/instances.rst 71 additions, 0 deletionsdocs/users_guide/exts/instances.rst
- docs/users_guide/exts/scoped_type_variables.rst 40 additions, 7 deletionsdocs/users_guide/exts/scoped_type_variables.rst
- testsuite/tests/dependent/should_fail/T16326_Fail8.stderr 3 additions, 4 deletionstestsuite/tests/dependent/should_fail/T16326_Fail8.stderr
- testsuite/tests/dependent/should_fail/T18271.hs 7 additions, 0 deletionstestsuite/tests/dependent/should_fail/T18271.hs
- testsuite/tests/dependent/should_fail/T18271.stderr 5 additions, 0 deletionstestsuite/tests/dependent/should_fail/T18271.stderr
- testsuite/tests/dependent/should_fail/all.T 1 addition, 0 deletionstestsuite/tests/dependent/should_fail/all.T
- testsuite/tests/deriving/should_compile/T15831.hs 10 additions, 10 deletionstestsuite/tests/deriving/should_compile/T15831.hs
- testsuite/tests/deriving/should_compile/deriving-via-standalone.hs 3 additions, 3 deletions.../tests/deriving/should_compile/deriving-via-standalone.hs
- testsuite/tests/deriving/should_fail/deriving-via-fail.hs 1 addition, 1 deletiontestsuite/tests/deriving/should_fail/deriving-via-fail.hs
- testsuite/tests/deriving/should_fail/deriving-via-fail4.hs 1 addition, 1 deletiontestsuite/tests/deriving/should_fail/deriving-via-fail4.hs
- testsuite/tests/parser/should_fail/T3811c.stderr 4 additions, 3 deletionstestsuite/tests/parser/should_fail/T3811c.stderr
- testsuite/tests/rename/should_fail/T16114.stderr 3 additions, 5 deletionstestsuite/tests/rename/should_fail/T16114.stderr
- testsuite/tests/rename/should_fail/T18240a.hs 29 additions, 0 deletionstestsuite/tests/rename/should_fail/T18240a.hs
- testsuite/tests/rename/should_fail/T18240a.stderr 40 additions, 0 deletionstestsuite/tests/rename/should_fail/T18240a.stderr
- testsuite/tests/rename/should_fail/T18240b.hs 29 additions, 0 deletionstestsuite/tests/rename/should_fail/T18240b.hs
- testsuite/tests/rename/should_fail/T18240b.stderr 24 additions, 0 deletionstestsuite/tests/rename/should_fail/T18240b.stderr
Loading
Please register or sign in to comment