X-Git-Url: http://git.megacz.com/?p=ghc-hetmet.git;a=blobdiff_plain;f=compiler%2Frename%2FRnPat.lhs;h=bc174954787e022915dd776b2bb795f18bd47101;hp=63672553501c4ccd7f83d57c5766b942076264b7;hb=6f8ff0bbad3b9fa389c960ad1b5a267a1ae502f1;hpb=df8b00e014ad8280354dd3fab6e6df0a52377627 diff --git a/compiler/rename/RnPat.lhs b/compiler/rename/RnPat.lhs index 6367255..bc17495 100644 --- a/compiler/rename/RnPat.lhs +++ b/compiler/rename/RnPat.lhs @@ -11,7 +11,7 @@ free variables. \begin{code} module RnPat (-- main entry points - rnPats, rnBindPat, + rnPat, rnPats, rnBindPat, NameMaker, applyNameMaker, -- a utility for making names: localRecNameMaker, topRecNameMaker, -- sometimes we want to make local names, @@ -22,9 +22,6 @@ module RnPat (-- main entry points -- Literals rnLit, rnOverLit, - -- Quasiquotation - rnQuasiQuote, - -- Pattern Error messages that are also used elsewhere checkTupSize, patSigErr ) where @@ -133,9 +130,11 @@ which is how you go from a RdrName to a Name data NameMaker = LamMk -- Lambdas Bool -- True <=> report unused bindings + -- (even if True, the warning only comes out + -- if -fwarn-unused-matches is on) | LetMk -- Let bindings, incl top level - -- Do not check for unused bindings + -- Do *not* check for unused bindings (Maybe Module) -- Just m => top level of module m -- Nothing => not top level MiniFixityEnv @@ -146,8 +145,14 @@ topRecNameMaker mod fix_env = LetMk (Just mod) fix_env localRecNameMaker :: MiniFixityEnv -> NameMaker localRecNameMaker fix_env = LetMk Nothing fix_env -matchNameMaker :: NameMaker -matchNameMaker = LamMk True +matchNameMaker :: HsMatchContext a -> NameMaker +matchNameMaker ctxt = LamMk report_unused + where + -- Do not report unused names in interactive contexts + -- i.e. when you type 'x <- e' at the GHCi prompt + report_unused = case ctxt of + StmtCtxt GhciStmt -> False + _ -> True newName :: NameMaker -> Located RdrName -> CpsRn Name newName (LamMk report_unused) rdr_name @@ -212,8 +217,8 @@ rnPats ctxt pats thing_inside -- (0) bring into scope all of the type variables bound by the patterns -- (1) rename the patterns, bringing into scope all of the term variables -- (2) then do the thing inside. - ; bindPatSigTyVarsFV (collectSigTysFromPats pats) $ - unCpsRn (rnLPatsAndThen matchNameMaker pats) $ \ pats' -> do + ; bindPatSigTyVarsFV (collectSigTysFromPats pats) $ + unCpsRn (rnLPatsAndThen (matchNameMaker ctxt) pats) $ \ pats' -> do { -- Check for duplicated and shadowed names -- Because we don't bind the vars all at once, we can't -- check incrementally for duplicates; @@ -225,6 +230,12 @@ rnPats ctxt pats thing_inside where doc_pat = ptext (sLit "In") <+> pprMatchContext ctxt +rnPat :: HsMatchContext Name -- for error messages + -> LPat RdrName + -> (LPat Name -> RnM (a, FreeVars)) + -> RnM (a, FreeVars) +rnPat ctxt pat thing_inside + = rnPats ctxt [pat] (\[pat'] -> thing_inside pat') applyNameMaker :: NameMaker -> Located RdrName -> RnM Name applyNameMaker mk rdr = do { (n, _fvs) <- runCps (newName mk rdr); return n } @@ -355,8 +366,7 @@ rnPatAndThen _ p@(QuasiQuotePat {}) = pprPanic "Can't do QuasiQuotePat without GHCi" (ppr p) #else rnPatAndThen mk (QuasiQuotePat qq) - = do { qq' <- liftCpsFV $ rnQuasiQuote qq - ; pat <- liftCps $ runQuasiQuotePat qq' + = do { pat <- liftCps $ runQuasiQuotePat qq ; L _ pat' <- rnLPatAndThen mk pat ; return pat' } #endif /* GHCI */ @@ -557,27 +567,6 @@ rnOverLit lit@(OverLit {ol_val=val}) %************************************************************************ %* * -\subsubsection{Quasiquotation} -%* * -%************************************************************************ - -See Note [Quasi-quote overview] in TcSplice. - -\begin{code} -rnQuasiQuote :: HsQuasiQuote RdrName -> RnM (HsQuasiQuote Name, FreeVars) -rnQuasiQuote (HsQuasiQuote n quoter quoteSpan quote) - = do { loc <- getSrcSpanM - ; n' <- newLocalBndrRn (L loc n) - ; quoter' <- lookupOccRn quoter - -- If 'quoter' is not in scope, proceed no further - -- Otherwise lookupOcc adds an error messsage and returns - -- an "unubound name", which makes the subsequent attempt to - -- run the quote fail - ; return (HsQuasiQuote n' quoter' quoteSpan quote, unitFV quoter') } -\end{code} - -%************************************************************************ -%* * \subsubsection{Errors} %* * %************************************************************************