[commit: ghc] ghc-8.0: rename: Disallow type signatures in patterns in plain Haskell (0178633)
git at git.haskell.org
git at git.haskell.org
Tue Mar 29 17:38:38 UTC 2016
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-8.0
Link : http://ghc.haskell.org/trac/ghc/changeset/01786339bce247cc8ca008d2be20a7b4b5519d40/ghc
>---------------------------------------------------------------
commit 01786339bce247cc8ca008d2be20a7b4b5519d40
Author: Ben Gamari <bgamari.foss at gmail.com>
Date: Tue Mar 29 14:11:57 2016 +0200
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
(cherry picked from commit d5d6804d37960ece2652196f3661604a70c12ffc)
>---------------------------------------------------------------
01786339bce247cc8ca008d2be20a7b4b5519d40
compiler/rename/RnTypes.hs | 11 ++++++++++-
testsuite/tests/rename/should_fail/T11663.hs | 8 ++++++++
testsuite/tests/rename/should_fail/T11663.stderr | 16 ++++++++++++++++
testsuite/tests/rename/should_fail/all.T | 1 +
4 files changed, 35 insertions(+), 1 deletion(-)
diff --git a/compiler/rename/RnTypes.hs b/compiler/rename/RnTypes.hs
index fa15660..09f4ebb 100644
--- a/compiler/rename/RnTypes.hs
+++ b/compiler/rename/RnTypes.hs
@@ -88,8 +88,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
@@ -1393,6 +1397,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 0000000..2b8380f
--- /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 0000000..18ee6e6
--- /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 82d341b..e9ea297 100644
--- a/testsuite/tests/rename/should_fail/all.T
+++ b/testsuite/tests/rename/should_fail/all.T
@@ -140,3 +140,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
More information about the ghc-commits
mailing list