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/deriving | |
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/deriving')
4 files changed, 15 insertions, 15 deletions
diff --git a/testsuite/tests/deriving/should_compile/T15831.hs b/testsuite/tests/deriving/should_compile/T15831.hs index 309c8a8e3a..da157aa106 100644 --- a/testsuite/tests/deriving/should_compile/T15831.hs +++ b/testsuite/tests/deriving/should_compile/T15831.hs @@ -13,21 +13,21 @@ newtype Age = MkAge Int deriving Ord via Const Int (Any :: k) deriving Read - via (forall k. Const Int (Any :: k)) + via forall k. Const Int (Any :: k) deriving Show via Const Int a deriving Enum via Const Int (a :: k) deriving Bounded - via (forall a. Const Int a) + via forall a. Const Int a deriving Num - via (forall k (a :: k). Const Int a) + via forall k (a :: k). Const Int a newtype Age2 = MkAge2 Int -deriving via Const Int Any instance Eq Age2 -deriving via Const Int (Any :: k) instance Ord Age2 -deriving via (forall k. Const Int (Any :: k)) instance Read Age2 -deriving via Const Int a instance Show Age2 -deriving via Const Int (a :: k) instance Enum Age2 -deriving via (forall a. Const Int a) instance Bounded Age2 -deriving via (forall k (a :: k). Const Int a) instance Num Age2 +deriving via Const Int Any instance Eq Age2 +deriving via Const Int (Any :: k) instance Ord Age2 +deriving via forall k. Const Int (Any :: k) instance Read Age2 +deriving via Const Int a instance Show Age2 +deriving via Const Int (a :: k) instance Enum Age2 +deriving via forall a. Const Int a instance Bounded Age2 +deriving via forall k (a :: k). Const Int a instance Num Age2 diff --git a/testsuite/tests/deriving/should_compile/deriving-via-standalone.hs b/testsuite/tests/deriving/should_compile/deriving-via-standalone.hs index 26484a2df2..99da015bbd 100644 --- a/testsuite/tests/deriving/should_compile/deriving-via-standalone.hs +++ b/testsuite/tests/deriving/should_compile/deriving-via-standalone.hs @@ -37,6 +37,6 @@ data X1 a data X2 a data X3 a -deriving via (forall a. T a) instance Z a (X1 b) -deriving via (T a) instance forall b. Z a (X2 b) -deriving via (forall a. T a) instance forall b. Z a (X3 b) +deriving via forall a. T a instance Z a (X1 b) +deriving via T a instance forall b. Z a (X2 b) +deriving via forall a. T a instance forall b. Z a (X3 b) diff --git a/testsuite/tests/deriving/should_fail/deriving-via-fail.hs b/testsuite/tests/deriving/should_fail/deriving-via-fail.hs index 3fa8009638..0cb521de78 100644 --- a/testsuite/tests/deriving/should_fail/deriving-via-fail.hs +++ b/testsuite/tests/deriving/should_fail/deriving-via-fail.hs @@ -12,4 +12,4 @@ newtype Foo2 a b = Foo2 (a -> b) deriving Category via fooo -data Foo3 deriving Eq via (forall a. a) +data Foo3 deriving Eq via forall a. a diff --git a/testsuite/tests/deriving/should_fail/deriving-via-fail4.hs b/testsuite/tests/deriving/should_fail/deriving-via-fail4.hs index 1436d994c0..2e16abfa20 100644 --- a/testsuite/tests/deriving/should_fail/deriving-via-fail4.hs +++ b/testsuite/tests/deriving/should_fail/deriving-via-fail4.hs @@ -14,4 +14,4 @@ newtype F1 = F1 Int deriving Eq via Char newtype F2 a = MkF2 a - deriving (C a) via (forall a. a) + deriving (C a) via forall a. a |