diff options
author | Ryan Scott <ryan.gl.scott@gmail.com> | 2017-09-05 11:00:56 -0400 |
---|---|---|
committer | Ryan Scott <ryan.gl.scott@gmail.com> | 2017-09-05 11:00:57 -0400 |
commit | 0829821a6b886788a3ba6989e57e25a037bb6d05 (patch) | |
tree | 115a892a6df20303a7f0b65009f7afa589c14d2d /testsuite/tests/polykinds/T13985.hs | |
parent | 24e50f988f775c6bba7d1daaee2e23c13650aa3b (diff) | |
download | haskell-0829821a6b886788a3ba6989e57e25a037bb6d05.tar.gz |
Implicitly bind kind variables in type family instance RHSes when it's sensible
Summary:
Before, there was a discrepancy in how GHC renamed type synonyms as
opposed to type family instances. That is, GHC would accept definitions like
this one:
```lang=haskell
type T = (Nothing :: Maybe a)
```
However, it would not accept a very similar type family instance:
```lang=haskell
type family T :: Maybe a
type instance T = (Nothing :: Maybe a)
```
The primary goal of this patch is to bring the renaming of type family
instances up to par with that of type synonyms, causing the latter definition
to be accepted, and fixing #14131.
In particular, we now allow kind variables on the right-hand sides of type
(and data) family instances to be //implicitly// bound by LHS type (or kind)
patterns (as opposed to type variables, which must always be explicitly
bound by LHS type patterns only). As a consequence, this allows programs
reported in #7938 and #9574 to typecheck, whereas before they would
have been rejected.
Implementation-wise, there isn't much trickery involved in making this happen.
We simply need to bind additional kind variables from the RHS of a type family
in the right place (in particular, see `RnSource.rnFamInstEqn`, which has
undergone a minor facelift).
While doing this has the upside of fixing #14131, it also made it easier to
trigger #13985, so I decided to fix that while I was in town. This was
accomplished by a careful blast of `reportFloatingKvs` in `tcFamTyPats`.
Test Plan: ./validate
Reviewers: simonpj, goldfire, austin, bgamari
Reviewed By: simonpj
Subscribers: rwbarton, thomie
GHC Trac Issues: #13985, #14131
Differential Revision: https://phabricator.haskell.org/D3872
Diffstat (limited to 'testsuite/tests/polykinds/T13985.hs')
-rw-r--r-- | testsuite/tests/polykinds/T13985.hs | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/testsuite/tests/polykinds/T13985.hs b/testsuite/tests/polykinds/T13985.hs new file mode 100644 index 0000000000..c0555d8f69 --- /dev/null +++ b/testsuite/tests/polykinds/T13985.hs @@ -0,0 +1,27 @@ +{-# LANGUAGE DataKinds #-} +{-# LANGUAGE FlexibleInstances #-} +{-# LANGUAGE PolyKinds #-} +{-# LANGUAGE RankNTypes #-} +{-# LANGUAGE TypeFamilies #-} +module T13985 where + +import Data.Kind +import Data.Proxy + +data family Fam +data instance Fam = MkFam (forall (a :: k). Proxy a) + +type family T +type instance T = Proxy (Nothing :: Maybe a) + +class C k where + data CD :: k + type CT :: k + +instance C Type where + data CD = forall (a :: k). CD (Proxy a) + type CT = Proxy (Nothing :: Maybe a) + +class Z a where + type ZT a + type ZT a = Proxy (Nothing :: Maybe x) |