import RdrHsSyn
import RnHsSyn
import TcRnMonad
-import RnTypes ( rnHsSigType, rnLHsType, rnHsTypeFVs,checkPrecMatch)
+import RnTypes ( rnHsSigType, rnLHsType, checkPrecMatch)
import RnPat (rnPatsAndThen_LocalRightwards, rnBindPat,
- NameMaker, localRecNameMaker, topRecNameMaker, applyNameMaker,
- patSigErr)
+ NameMaker, localRecNameMaker, topRecNameMaker, applyNameMaker
+ )
import RnEnv
import PrelNames ( mkUnboundName )
import SrcLoc
import ListSetOps ( findDupsEq )
import BasicTypes ( RecFlag(..) )
-import Digraph ( SCC(..), stronglyConnComp )
+import Digraph ( SCC(..), stronglyConnCompFromEdgedVertices )
import Bag
import Outputable
import FastString
depAnalBinds binds_w_dus
= (map get_binds sccs, map get_du sccs)
where
- sccs = stronglyConnComp edges
+ sccs = stronglyConnCompFromEdgedVertices edges
keyd_nodes = bagToList binds_w_dus `zip` [0::Int ..]
renameSig :: Maybe NameSet -> Sig RdrName -> RnM (Sig Name)
-- FixitySig is renamed elsewhere.
renameSig mb_names sig@(TypeSig v ty)
- = do { new_v <- lookupSigOccRn mb_names sig v
+ = do { new_v <- lookupSigLocOccRn mb_names sig v
; new_ty <- rnHsSigType (quotes (ppr v)) ty
; return (TypeSig new_v new_ty) }
; return (SpecInstSig new_ty) }
renameSig mb_names sig@(SpecSig v ty inl)
- = do { new_v <- lookupSigOccRn mb_names sig v
+ = do { new_v <- lookupSigLocOccRn mb_names sig v
; new_ty <- rnHsSigType (quotes (ppr v)) ty
; return (SpecSig new_v new_ty inl) }
renameSig mb_names sig@(InlineSig v s)
- = do { new_v <- lookupSigOccRn mb_names sig v
+ = do { new_v <- lookupSigLocOccRn mb_names sig v
; return (InlineSig new_v s) }
renameSig mb_names sig@(FixSig (FixitySig v f))
- = do { new_v <- lookupSigOccRn mb_names sig v
+ = do { new_v <- lookupSigLocOccRn mb_names sig v
; return (FixSig (FixitySig new_v f)) }
-- lookupSigOccRn is used for type signatures and pragmas
-- return the imported 'f', so that later on the reanamer will
-- correctly report "misplaced type sig".
-lookupSigOccRn :: Maybe NameSet -> Sig RdrName -> Located RdrName -> RnM (Located Name)
-lookupSigOccRn mb_names sig (L loc v)
+lookupSigLocOccRn :: Maybe NameSet -> Sig RdrName -> Located RdrName -> RnM (Located Name)
+lookupSigLocOccRn mb_names sig = wrapLocM (lookupSigOccRn mb_names sig)
+
+lookupSigOccRn :: Maybe NameSet -> Sig RdrName -> RdrName -> RnM Name
+lookupSigOccRn mb_names sig v
= do { mb_n <- lookupBndrRn_maybe v
; case mb_n of {
Just n -> case mb_names of {
- Nothing -> return (L loc n) ;
- Just ns | n `elemNameSet` ns -> return (L loc n)
+ Nothing -> return n ;
+ Just ns | n `elemNameSet` ns -> return n
| otherwise -> bale_out_with local_msg } ;
Nothing -> do
<+> ptext (sLit "for") <+> quotes (ppr v)
, nest 2 $ ptext (sLit "lacks an accompanying binding")]
$$ nest 2 msg)
- ; return (L loc (mkUnboundName v)) }
+ ; return (mkUnboundName v) }
local_msg = parens $ ptext (sLit "The") <+> hsSigDoc sig <+> ptext (sLit "must be given where")
<+> quotes (ppr v) <+> ptext (sLit "is declared")
\end{code}
-************************************************************************
-* *
+%************************************************************************
+%* *
\subsection{Match}
-* *
-************************************************************************
+%* *
+%************************************************************************
\begin{code}
rnMatchGroup :: HsMatchContext Name -> MatchGroup RdrName -> RnM (MatchGroup Name, FreeVars)
rnMatch ctxt = wrapLocFstM (rnMatch' ctxt)
rnMatch' :: HsMatchContext Name -> Match RdrName -> RnM (Match Name, FreeVars)
-rnMatch' ctxt (Match pats maybe_rhs_sig grhss)
- =
- -- Deal with the rhs type signature
- bindPatSigTyVarsFV rhs_sig_tys $ do
- opt_PatternSignatures <- doptM Opt_PatternSignatures
- (maybe_rhs_sig', ty_fvs) <-
- case maybe_rhs_sig of
- Nothing -> return (Nothing, emptyFVs)
- Just ty | opt_PatternSignatures -> do (ty', ty_fvs) <- rnHsTypeFVs doc_sig ty
- return (Just ty', ty_fvs)
- | otherwise -> do addLocErr ty patSigErr
- return (Nothing, emptyFVs)
-
- -- Now the main event
- -- note that there are no local ficity decls for matches
- rnPatsAndThen_LocalRightwards ctxt pats $ \ pats' -> do
- (grhss', grhss_fvs) <- rnGRHSs ctxt grhss
-
- return (Match pats' maybe_rhs_sig' grhss', grhss_fvs `plusFV` ty_fvs)
+rnMatch' ctxt match@(Match pats maybe_rhs_sig grhss)
+ = do { -- Result type signatures are no longer supported
+ case maybe_rhs_sig of
+ Nothing -> return ()
+ Just ty -> addLocErr ty (resSigErr ctxt match)
+
+
+ -- Now the main event
+ -- note that there are no local ficity decls for matches
+ ; rnPatsAndThen_LocalRightwards ctxt pats $ \ pats' -> do
+ { (grhss', grhss_fvs) <- rnGRHSs ctxt grhss
+
+ ; return (Match pats' Nothing grhss', grhss_fvs) }}
-- The bindPatSigTyVarsFV and rnPatsAndThen will remove the bound FVs
where
- rhs_sig_tys = case maybe_rhs_sig of
- Nothing -> []
- Just ty -> [ty]
- doc_sig = text "In a result type-signature"
+
+resSigErr :: HsMatchContext Name -> Match RdrName -> HsType RdrName -> SDoc
+resSigErr ctxt match ty
+ = vcat [ ptext (sLit "Illegal result type signature") <+> quotes (ppr ty)
+ , nest 2 $ ptext (sLit "Result signatures are no longer supported in pattern matches")
+ , pprMatchInCtxt ctxt match ]
\end{code}