summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Gamari <bgamari.foss@gmail.com>2016-03-29 14:11:57 +0200
committerBen Gamari <ben@smart-cactus.org>2016-03-29 18:58:39 +0200
commitd5d6804d37960ece2652196f3661604a70c12ffc (patch)
treed3c6c22778b04abfa4c2a0855066917b62f340ae
parentcf768ec062dee47cf72cbddf42d69d9508ec3afb (diff)
downloadhaskell-d5d6804d37960ece2652196f3661604a70c12ffc.tar.gz
rename: Disallow type signatures in patterns in plain Haskell
This should require -XScopedTypeVariables. It seems this was previously handled by RnTypes.rnHsBndrSig which called RnTypes.badKindSigErr but this was broken in Simon's refactor of wildcards, 1e041b7382b6aa329e4ad9625439f811e0f27232. Here we re-introduce a check in RnPat. See #11663. Test Plan: Validate with `T11663` Reviewers: austin, simonpj Reviewed By: austin Subscribers: thomie Differential Revision: https://phabricator.haskell.org/D2054 GHC Trac Issues: #11663
-rw-r--r--compiler/rename/RnTypes.hs11
-rw-r--r--testsuite/tests/rename/should_fail/T11663.hs8
-rw-r--r--testsuite/tests/rename/should_fail/T11663.stderr16
-rw-r--r--testsuite/tests/rename/should_fail/all.T1
4 files changed, 35 insertions, 1 deletions
diff --git a/compiler/rename/RnTypes.hs b/compiler/rename/RnTypes.hs
index d14769ee71..7a9f75d7aa 100644
--- a/compiler/rename/RnTypes.hs
+++ b/compiler/rename/RnTypes.hs
@@ -84,8 +84,12 @@ rnHsSigWcTypeScoped :: HsDocContext -> LHsSigWcType RdrName
-- - Signatures on binders in a RULE
-- - Pattern type signatures
-- Wildcards are allowed
+-- type signatures on binders only allowed with ScopedTypeVariables
rnHsSigWcTypeScoped ctx sig_ty thing_inside
- = rn_hs_sig_wc_type False ctx sig_ty thing_inside
+ = do { ty_sig_okay <- xoptM LangExt.ScopedTypeVariables
+ ; checkErr ty_sig_okay (unexpectedTypeSigErr sig_ty)
+ ; rn_hs_sig_wc_type False ctx sig_ty thing_inside
+ }
-- False: for pattern type sigs and rules we /do/ want
-- to bring those type variables into scope
-- e.g \ (x :: forall a. a-> b) -> e
@@ -1389,6 +1393,11 @@ ppr_opfix (op, fixity) = pp_op <+> brackets (ppr fixity)
* *
***************************************************** -}
+unexpectedTypeSigErr :: LHsSigWcType RdrName -> SDoc
+unexpectedTypeSigErr ty
+ = hang (text "Illegal type signature:" <+> quotes (ppr ty))
+ 2 (text "Type signatures are only allowed in patterns with ScopedTypeVariables")
+
badKindBndrs :: HsDocContext -> [Located RdrName] -> SDoc
badKindBndrs doc kvs
= withHsDocContext doc $
diff --git a/testsuite/tests/rename/should_fail/T11663.hs b/testsuite/tests/rename/should_fail/T11663.hs
new file mode 100644
index 0000000000..2b8380fba1
--- /dev/null
+++ b/testsuite/tests/rename/should_fail/T11663.hs
@@ -0,0 +1,8 @@
+module T11663 where
+
+-- All of these should fail as type signatures are not allowed
+-- in patterns without -XScopedTypeVariables.
+hello0 = \(h :: Int) -> print h
+hello1 (h :: Int) = print h
+hello2 = case 54 of (x :: Int) -> print x
+hello4 = case Just 54 of Just (x :: Int) -> print x
diff --git a/testsuite/tests/rename/should_fail/T11663.stderr b/testsuite/tests/rename/should_fail/T11663.stderr
new file mode 100644
index 0000000000..18ee6e62d1
--- /dev/null
+++ b/testsuite/tests/rename/should_fail/T11663.stderr
@@ -0,0 +1,16 @@
+
+T11663.hs:5:12: error:
+ Illegal type signature: ‘Int’
+ Type signatures are only allowed in patterns with ScopedTypeVariables
+
+T11663.hs:6:9: error:
+ Illegal type signature: ‘Int’
+ Type signatures are only allowed in patterns with ScopedTypeVariables
+
+T11663.hs:7:22: error:
+ Illegal type signature: ‘Int’
+ Type signatures are only allowed in patterns with ScopedTypeVariables
+
+T11663.hs:8:32: error:
+ Illegal type signature: ‘Int’
+ Type signatures are only allowed in patterns with ScopedTypeVariables
diff --git a/testsuite/tests/rename/should_fail/all.T b/testsuite/tests/rename/should_fail/all.T
index ebe67976aa..195b7296d9 100644
--- a/testsuite/tests/rename/should_fail/all.T
+++ b/testsuite/tests/rename/should_fail/all.T
@@ -137,3 +137,4 @@ test('T5001b', normal, compile_fail, [''])
test('T10781', normal, compile_fail, [''])
test('T11071', normal, compile_fail, [''])
test('T11071a', normal, compile_fail, [''])
+test('T11663', normal, compile_fail, ['']) \ No newline at end of file