summaryrefslogtreecommitdiff
path: root/testsuite/tests/dependent/should_fail
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2020-05-21 12:01:06 -0400
committerMarge Bot <ben+marge-bot@smart-cactus.org>2020-06-09 08:06:24 -0400
commit72c7fe9a1e147dfeaf043f6d591d724a126cce45 (patch)
tree89c4eb7ba14900e32a6b48c7e73ececcc0b1a4d4 /testsuite/tests/dependent/should_fail
parent9b607671b9158c60470b2bd57804a7684d3ea33f (diff)
downloadhaskell-72c7fe9a1e147dfeaf043f6d591d724a126cce45.tar.gz
Make GADT constructors adhere to the forall-or-nothing rule properly
Issue #18191 revealed that the types of GADT constructors don't quite adhere to the `forall`-or-nothing rule. This patch serves to clean up this sad state of affairs somewhat. The main change is not in the code itself, but in the documentation, as this patch introduces two sections to the GHC User's Guide: * A "Formal syntax for GADTs" section that presents a BNF-style grammar for what is and isn't allowed in GADT constructor types. This mostly exists to codify GHC's existing behavior, but it also imposes a new restriction that addresses #18191: the outermost `forall` and/or context in a GADT constructor is not allowed to be surrounded by parentheses. Doing so would make these `forall`s/contexts nested, and GADTs do not support nested `forall`s/contexts at present. * A "`forall`-or-nothing rule" section that describes exactly what the `forall`-or-nothing rule is all about. Surprisingly, there was no mention of this anywhere in the User's Guide up until now! To adhere the new specification in the "Formal syntax for GADTs" section of the User's Guide, the following code changes were made: * A new function, `GHC.Hs.Type.splitLHsGADTPrefixTy`, was introduced. This is very much like `splitLHsSigmaTy`, except that it avoids splitting apart any parentheses, which can be syntactically significant for GADT types. See `Note [No nested foralls or contexts in GADT constructors]` in `GHC.Hs.Type`. * `ConDeclGADTPrefixPs`, an extension constructor for `XConDecl`, was introduced so that `GHC.Parser.PostProcess.mkGadtDecl` can return it when given a prefix GADT constructor. Unlike `ConDeclGADT`, `ConDeclGADTPrefixPs` does not split the GADT type into its argument and result types, as this cannot be done until after the type is renamed (see `Note [GADT abstract syntax]` in `GHC.Hs.Decls` for why this is the case). * `GHC.Renamer.Module.rnConDecl` now has an additional case for `ConDeclGADTPrefixPs` that (1) splits apart the full `LHsType` into its `forall`s, context, argument types, and result type, and (2) checks for nested `forall`s/contexts. Step (2) used to be performed the typechecker (in `GHC.Tc.TyCl.badDataConTyCon`) rather than the renamer, but now the relevant code from the typechecker can simply be deleted. One nice side effect of this change is that we are able to give a more accurate error message for GADT constructors that use visible dependent quantification (e.g., `MkFoo :: forall a -> a -> Foo a`), which improves the stderr in the `T16326_Fail6` test case. Fixes #18191. Bumps the Haddock submodule.
Diffstat (limited to 'testsuite/tests/dependent/should_fail')
-rw-r--r--testsuite/tests/dependent/should_fail/T16326_Fail6.stderr10
1 files changed, 4 insertions, 6 deletions
diff --git a/testsuite/tests/dependent/should_fail/T16326_Fail6.stderr b/testsuite/tests/dependent/should_fail/T16326_Fail6.stderr
index bb78e2f457..e4acd7a7fd 100644
--- a/testsuite/tests/dependent/should_fail/T16326_Fail6.stderr
+++ b/testsuite/tests/dependent/should_fail/T16326_Fail6.stderr
@@ -1,7 +1,5 @@
-T16326_Fail6.hs:9:3: error:
- • GADT constructor type signature cannot contain nested ‘forall’s or contexts
- Suggestion: instead use this type signature:
- MkFoo :: forall a. a -> Foo a
- • In the definition of data constructor ‘MkFoo’
- In the data type declaration for ‘Foo’
+T16326_Fail6.hs:9:12: error:
+ Illegal visible, dependent quantification in the type of a term
+ (GHC does not yet support this)
+ In the definition of data constructor ‘MkFoo’