diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2020-06-09 18:13:35 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-06-30 07:10:42 -0400 |
commit | 71006532abb88a53df7c7e0b3a5e2c8af99a48d1 (patch) | |
tree | d8874dbdd68ce911a83374dd6e241a80153553fc /testsuite/tests/dependent | |
parent | bfa5698b1ab0190820a2df19487d3d72d3a7924d (diff) | |
download | haskell-71006532abb88a53df7c7e0b3a5e2c8af99a48d1.tar.gz |
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.
Diffstat (limited to 'testsuite/tests/dependent')
4 files changed, 16 insertions, 4 deletions
diff --git a/testsuite/tests/dependent/should_fail/T16326_Fail8.stderr b/testsuite/tests/dependent/should_fail/T16326_Fail8.stderr index 16c2aa617e..d7666cf84d 100644 --- a/testsuite/tests/dependent/should_fail/T16326_Fail8.stderr +++ b/testsuite/tests/dependent/should_fail/T16326_Fail8.stderr @@ -1,6 +1,5 @@ T16326_Fail8.hs:7:10: error: - Illegal class instance: ‘forall a -> C (Blah a)’ - Class instances must be of the form - context => C ty_1 ... ty_n - where ‘C’ is a class + Illegal visible, dependent quantification in the type of a term + (GHC does not yet support this) + In an instance declaration diff --git a/testsuite/tests/dependent/should_fail/T18271.hs b/testsuite/tests/dependent/should_fail/T18271.hs new file mode 100644 index 0000000000..2441fa7318 --- /dev/null +++ b/testsuite/tests/dependent/should_fail/T18271.hs @@ -0,0 +1,7 @@ +{-# LANGUAGE DeriveAnyClass #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE StandaloneDeriving #-} +module T18271 where + +class C a +deriving instance forall a -> C (Maybe a) diff --git a/testsuite/tests/dependent/should_fail/T18271.stderr b/testsuite/tests/dependent/should_fail/T18271.stderr new file mode 100644 index 0000000000..0bc21f394d --- /dev/null +++ b/testsuite/tests/dependent/should_fail/T18271.stderr @@ -0,0 +1,5 @@ + +T18271.hs:7:19: error: + Illegal visible, dependent quantification in the type of a term + (GHC does not yet support this) + In a deriving declaration diff --git a/testsuite/tests/dependent/should_fail/all.T b/testsuite/tests/dependent/should_fail/all.T index d3d155f163..38c7f45d55 100644 --- a/testsuite/tests/dependent/should_fail/all.T +++ b/testsuite/tests/dependent/should_fail/all.T @@ -65,3 +65,4 @@ test('T14880-2', normal, compile_fail, ['']) test('T15076', normal, compile_fail, ['']) test('T15076b', normal, compile_fail, ['']) test('T17687', normal, compile_fail, ['']) +test('T18271', normal, compile_fail, ['']) |