[commit: ghc] master: rename: Disallow type signatures in patterns in plain Haskell (d5d6804)

git at git.haskell.org git at git.haskell.org
Tue Mar 29 16:56:20 UTC 2016


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/d5d6804d37960ece2652196f3661604a70c12ffc/ghc

>---------------------------------------------------------------

commit d5d6804d37960ece2652196f3661604a70c12ffc
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


>---------------------------------------------------------------

d5d6804d37960ece2652196f3661604a70c12ffc
 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 d14769e..7a9f75d 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 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 ebe6797..195b729 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



More information about the ghc-commits mailing list