Commit d5d6804d authored by Ben Gamari's avatar Ben Gamari Committed by Ben Gamari
Browse files

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,
1e041b73. 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
parent cf768ec0
......@@ -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 $
......
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
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
......@@ -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
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment