diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2020-06-29 20:19:41 -0400 |
---|---|---|
committer | Marge Bot <ben+marge-bot@smart-cactus.org> | 2020-07-01 15:44:01 -0400 |
commit | 76d8cc744977d98f6a427b1816198709e2d2e856 (patch) | |
tree | 01d56926bea8d5acc23d91b0809b3955073c7204 /testsuite | |
parent | 5c9fabb82b39aed9e61c6b78c72312b20a568c68 (diff) | |
download | haskell-76d8cc744977d98f6a427b1816198709e2d2e856.tar.gz |
Desugar quoted uses of DerivingVia and expression type signatures properly
The way that `GHC.HsToCore.Quote` desugared quoted `via` types (e.g.,
`deriving via forall a. [a] instance Eq a => Eq (List a)`) and
explicit type annotations in signatures (e.g.,
`f = id @a :: forall a. a -> a`) was completely wrong, as it did not
implement the scoping guidelines laid out in
`Note [Scoped type variables in bindings]`. This is easily fixed.
While I was in town, I did some minor cleanup of related Notes:
* `Note [Scoped type variables in bindings]` and
`Note [Scoped type variables in class and instance declarations]`
say very nearly the same thing. I decided to just consolidate the
two Notes into `Note [Scoped type variables in quotes]`.
* `Note [Don't quantify implicit type variables in quotes]` is
somewhat outdated, as it predates GHC 8.10, where the
`forall`-or-nothing rule requires kind variables to be explicitly
quantified in the presence of an explicit `forall`. As a result,
the running example in that Note doesn't even compile. I have
changed the example to something simpler that illustrates the
same point that the original Note was making.
Fixes #18388.
Diffstat (limited to 'testsuite')
-rw-r--r-- | testsuite/tests/th/T18388.hs | 29 | ||||
-rw-r--r-- | testsuite/tests/th/all.T | 1 |
2 files changed, 30 insertions, 0 deletions
diff --git a/testsuite/tests/th/T18388.hs b/testsuite/tests/th/T18388.hs new file mode 100644 index 0000000000..d31758004b --- /dev/null +++ b/testsuite/tests/th/T18388.hs @@ -0,0 +1,29 @@ +{-# LANGUAGE DerivingVia #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE MultiParamTypeClasses #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE StandaloneDeriving #-} +{-# LANGUAGE TemplateHaskell #-} +{-# LANGUAGE TypeApplications #-} +module T18388 where + +class C x y where + m :: x -> y -> y + +newtype Tagged x a = MkTagged a +instance C x (Tagged x a) where + m _ = id + +$([d| newtype Id1 a = MkId1 a + deriving (C x) via forall x. Tagged x a + + newtype Id2 a = MkId2 a + deriving (C x) via Tagged x a + |]) + +newtype List1 a = MkList1 [a] +newtype List2 a = MkList2 [a] +$([d| deriving via forall a. [a] instance Eq a => Eq (List1 a) |]) +$([d| deriving via [a] instance Eq a => Eq (List2 a) |]) + +$([d| f = id @a :: forall a. a -> a |]) diff --git a/testsuite/tests/th/all.T b/testsuite/tests/th/all.T index e224641c92..24cc9d9b46 100644 --- a/testsuite/tests/th/all.T +++ b/testsuite/tests/th/all.T @@ -510,3 +510,4 @@ test('TH_StringLift', normal, compile, ['']) test('TH_BytesShowEqOrd', normal, compile_and_run, ['']) test('T18121', normal, compile, ['']) test('T18123', normal, compile, ['']) +test('T18388', normal, compile, ['']) |