summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Eisenberg <rae@cs.brynmawr.edu>2017-07-18 19:49:38 (GMT)
committerRichard Eisenberg <rae@cs.brynmawr.edu>2017-07-27 11:49:06 (GMT)
commit10d13b62c7ba8c44000a0d25afd66788de8040c4 (patch)
tree982b62065d2459021ad5b68bd33973029b594ff2
parentfb752133f45f01b27240d7cc6bce2063a015e51b (diff)
downloadghc-10d13b62c7ba8c44000a0d25afd66788de8040c4.zip
ghc-10d13b62c7ba8c44000a0d25afd66788de8040c4.tar.gz
ghc-10d13b62c7ba8c44000a0d25afd66788de8040c4.tar.bz2
Fix #11963 by checking for more mixed type/kinds
This is a straightforward fix -- there were just some omitted checks. test case: typecheck/should_fail/T11963
-rw-r--r--compiler/rename/RnTypes.hs25
-rw-r--r--testsuite/tests/typecheck/should_fail/T11963.hs29
-rw-r--r--testsuite/tests/typecheck/should_fail/T11963.stderr20
-rw-r--r--testsuite/tests/typecheck/should_fail/all.T2
4 files changed, 70 insertions, 6 deletions
diff --git a/compiler/rename/RnTypes.hs b/compiler/rename/RnTypes.hs
index 014d485..a0ceb32 100644
--- a/compiler/rename/RnTypes.hs
+++ b/compiler/rename/RnTypes.hs
@@ -1717,11 +1717,25 @@ extract_hs_tv_bndrs tvs
= do { FKTV bndr_kvs _
<- foldrM extract_lkind emptyFKTV [k | L _ (KindedTyVar _ k) <- tvs]
- ; let locals = map hsLTyVarName tvs
+ ; let locals = map hsLTyVarLocName tvs
+
+ -- These checks are all tested in typecheck/should_fail/T11963
+ ; check_for_mixed_vars bndr_kvs acc_tvs
+ ; check_for_mixed_vars bndr_kvs body_tvs
+ ; check_for_mixed_vars body_tvs acc_kvs
+ ; check_for_mixed_vars body_kvs acc_tvs
+ ; check_for_mixed_vars locals body_kvs
+
; return $
- FKTV (filterOut ((`elem` locals) . unLoc) (bndr_kvs ++ body_kvs)
+ FKTV (filterOut (`elemRdr` locals) (bndr_kvs ++ body_kvs)
++ acc_kvs)
- (filterOut ((`elem` locals) . unLoc) body_tvs ++ acc_tvs) }
+ (filterOut (`elemRdr` locals) body_tvs ++ acc_tvs) }
+ where
+ check_for_mixed_vars :: [Located RdrName] -> [Located RdrName] -> RnM ()
+ check_for_mixed_vars tvs1 tvs2 = mapM_ check tvs1
+ where
+ check tv1 = when (isRdrTyVar (unLoc tv1) && (tv1 `elemRdr` tvs2)) $
+ mixedVarsErr tv1
extract_tv :: TypeOrKind -> Located RdrName -> FreeKiTyVars
-> RnM FreeKiTyVars
@@ -1737,8 +1751,6 @@ extract_tv t_or_k ltv@(L _ tv) acc
mixedVarsErr ltv
; return (FKTV (ltv : kvs) tvs) }
| otherwise = return acc
- where
- elemRdr x = any (eqLocated x)
mixedVarsErr :: Located RdrName -> RnM ()
mixedVarsErr (L loc tv)
@@ -1751,3 +1763,6 @@ mixedVarsErr (L loc tv)
-- just used in this module; seemed convenient here
nubL :: Eq a => [Located a] -> [Located a]
nubL = nubBy eqLocated
+
+elemRdr :: Located RdrName -> [Located RdrName] -> Bool
+elemRdr x = any (eqLocated x)
diff --git a/testsuite/tests/typecheck/should_fail/T11963.hs b/testsuite/tests/typecheck/should_fail/T11963.hs
new file mode 100644
index 0000000..c4f78ae
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T11963.hs
@@ -0,0 +1,29 @@
+{-# LANGUAGE GADTs, PolyKinds, RankNTypes #-}
+
+module T11963 where
+
+-- this module should be rejected without TypeInType
+
+import Data.Proxy
+
+-- see code in RnTypes.extract_hs_tv_bndrs which checks for these bad cases
+
+ -- bndr_kvs vs body_tvs
+data Typ k t where
+ Typ :: (forall (a :: k -> *). a t -> a t) -> Typ k t
+
+ -- bndr_kvs vs acc_tvs
+foo :: (forall (t :: k). Proxy t) -> Proxy k
+foo _ = undefined
+
+ -- locals vs body_kvs
+bar :: forall k. forall (t :: k). Proxy t
+bar = undefined
+
+ -- body_kvs vs acc_tvs
+quux :: (forall t. Proxy (t :: k)) -> Proxy k
+quux _ = undefined
+
+ -- body_tvs vs acc_kvs
+blargh :: (forall a. a -> Proxy k) -> Proxy (t :: k)
+blargh _ = undefined
diff --git a/testsuite/tests/typecheck/should_fail/T11963.stderr b/testsuite/tests/typecheck/should_fail/T11963.stderr
new file mode 100644
index 0000000..74c3ab0
--- /dev/null
+++ b/testsuite/tests/typecheck/should_fail/T11963.stderr
@@ -0,0 +1,20 @@
+
+T11963.hs:13:26: error:
+ Variable ‘k’ used as both a kind and a type
+ Did you intend to use TypeInType?
+
+T11963.hs:16:22: error:
+ Variable ‘k’ used as both a kind and a type
+ Did you intend to use TypeInType?
+
+T11963.hs:20:15: error:
+ Variable ‘k’ used as both a kind and a type
+ Did you intend to use TypeInType?
+
+T11963.hs:24:32: error:
+ Variable ‘k’ used as both a kind and a type
+ Did you intend to use TypeInType?
+
+T11963.hs:28:33: error:
+ Variable ‘k’ used as both a kind and a type
+ Did you intend to use TypeInType?
diff --git a/testsuite/tests/typecheck/should_fail/all.T b/testsuite/tests/typecheck/should_fail/all.T
index 58ae57f..3d2a595 100644
--- a/testsuite/tests/typecheck/should_fail/all.T
+++ b/testsuite/tests/typecheck/should_fail/all.T
@@ -451,4 +451,4 @@ test('T12373', normal, compile_fail, [''])
test('T13610', normal, compile_fail, [''])
test('T11672', normal, compile_fail, [''])
test('T13819', normal, compile_fail, [''])
-
+test('T11963', normal, compile_fail, [''])