summaryrefslogtreecommitdiff
path: root/compiler/GHC/Rename/HsType.hs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/GHC/Rename/HsType.hs')
-rw-r--r--compiler/GHC/Rename/HsType.hs45
1 files changed, 31 insertions, 14 deletions
diff --git a/compiler/GHC/Rename/HsType.hs b/compiler/GHC/Rename/HsType.hs
index 049bbe2c22..7ab390615a 100644
--- a/compiler/GHC/Rename/HsType.hs
+++ b/compiler/GHC/Rename/HsType.hs
@@ -31,7 +31,8 @@ module GHC.Rename.HsType (
-- Binding related stuff
bindHsOuterTyVarBndrs, bindHsForAllTelescope,
bindLHsTyVarBndr, bindLHsTyVarBndrs, WarnUnusedForalls(..),
- rnImplicitTvOccs, bindSigTyVarsFV, bindHsQTyVars,
+ rnImplicitTvOccs, bindSigTyVarsFVExtended, bindSigTyVarsFVMethod,
+ bindHsQTyVars,
FreeKiTyVars, filterInScopeM,
extractHsTyRdrTyVars, extractHsTyRdrTyVarsKindVars,
extractHsTysRdrTyVars, extractRdrKindSigVars,
@@ -150,14 +151,14 @@ rnHsPatSigType :: HsPatSigTypeScoping
-> (HsPatSigType GhcRn -> RnM (a, FreeVars))
-> RnM (a, FreeVars)
-- Used for
--- - Pattern type signatures, which are only allowed with ScopedTypeVariables
+-- - Pattern type signatures, which are only allowed with PatternSignatures
-- - Signatures on binders in a RULE, which are allowed even if
--- ScopedTypeVariables isn't enabled
+-- PatternSignatures isn't enabled
-- Wildcards are allowed
--
-- See Note [Pattern signature binders and scoping] in GHC.Hs.Type
rnHsPatSigType scoping ctx sig_ty thing_inside
- = do { ty_sig_okay <- xoptM LangExt.ScopedTypeVariables
+ = do { ty_sig_okay <- xoptM LangExt.PatternSignatures
; checkErr ty_sig_okay (unexpectedPatSigTypeErr sig_ty)
; free_vars <- filterInScopeM (extractHsTyRdrTyVars pat_sig_ty)
; (nwc_rdrs', tv_rdrs) <- partition_nwcs free_vars
@@ -165,6 +166,9 @@ rnHsPatSigType scoping ctx sig_ty thing_inside
implicit_bndrs = case scoping of
AlwaysBind -> tv_rdrs
NeverBind -> []
+ ; let i_bndrs = nubN implicit_bndrs in
+ unless (null i_bndrs) $
+ addDiagnostic (TcRnPatternSignatureBinds i_bndrs)
; rnImplicitTvOccs Nothing implicit_bndrs $ \ imp_tvs ->
do { (nwcs, pat_sig_ty', fvs1) <- rnWcBody ctx nwc_rdrs pat_sig_ty
; let sig_names = HsPSRn { hsps_nwcs = nwcs, hsps_imp_tvs = imp_tvs }
@@ -386,6 +390,10 @@ rnImplicitTvOccs :: Maybe assoc
-> RnM (a, FreeVars)
rnImplicitTvOccs mb_assoc implicit_vs_with_dups thing_inside
= do { let implicit_vs = nubN implicit_vs_with_dups
+ ; unlessXOptM LangExt.ImplicitForAll $
+ unless (null implicit_vs) $
+ addErr (TcRnImplicitForAll implicit_vs)
+
; mapM_ warn_term_var_capture implicit_vs
; traceRn "rnImplicitTvOccs" $
@@ -900,18 +908,27 @@ notInKinds _ _ = return ()
* *
***************************************************** -}
-bindSigTyVarsFV :: [Name]
- -> RnM (a, FreeVars)
- -> RnM (a, FreeVars)
+bindSigTyVarsFVExtended, bindSigTyVarsFVMethod :: [Name]
+ -> RnM (a, FreeVars)
+ -> RnM (a, FreeVars)
-- Used just before renaming the defn of a function
-- with a separate type signature, to bring its tyvars into scope
--- With no -XScopedTypeVariables, this is a no-op
-bindSigTyVarsFV tvs thing_inside
- = do { scoped_tyvars <- xoptM LangExt.ScopedTypeVariables
- ; if not scoped_tyvars then
- thing_inside
- else
- bindLocalNamesFV tvs thing_inside }
+-- With no -XExtendedForAllScope/-XMethodTypeVariables, this is a no-op
+(bindSigTyVarsFVExtended, bindSigTyVarsFVMethod)
+ = ( bindSigTyVarsFVIfEnabled LangExt.ExtendedForAllScope
+ , bindSigTyVarsFVIfEnabled LangExt.MethodTypeVariables
+ )
+ where
+ bindSigTyVarsFVIfEnabled :: LangExt.Extension
+ -> [Name]
+ -> RnM (a, FreeVars)
+ -> RnM (a, FreeVars)
+ bindSigTyVarsFVIfEnabled lang_ext tvs thing_inside
+ = do { can_tyvars_be_in_scope <- xoptM lang_ext
+ ; if not can_tyvars_be_in_scope then
+ thing_inside
+ else
+ bindLocalNamesFV tvs thing_inside }
---------------
bindHsQTyVars :: forall a b.