\begin{code}
module RnBinds (
rnTopMonoBinds, rnMonoBinds, rnMonoBindsAndThen,
- rnMethodBinds, renameSigs, checkSigs, unknownSigErr
+ rnMethodBinds, renameSigs, checkSigs
) where
#include "HsVersions.h"
import HsSyn
-import HsBinds ( eqHsSig, hsSigDoc )
+import HsBinds ( hsSigDoc, sigLoc, eqHsSig )
import RdrHsSyn
import RnHsSyn
import TcRnMonad
import Digraph ( SCC(..), stronglyConnComp )
import Name ( Name, nameOccName, nameSrcLoc )
import NameSet
+import PrelNames ( isUnboundName )
import RdrName ( RdrName, rdrNameOcc )
import BasicTypes ( RecFlag(..), TopLevelFlag(..), isTopLevel )
import List ( unzip4 )
-> RnM (RenamedHsBinds, DefUses)
-- The binders of the binding are in scope already;
--- the top level scope resoluttion does that
+-- the top level scope resolution does that
rnTopMonoBinds mbinds sigs
= bindPatSigTyVars (collectSigTysFromMonoBinds mbinds) $ \ _ ->
let
all_uses = duUses bind_dus `plusFV` result_fvs
bndrs = duDefs bind_dus
- real_uses = findUses bind_dus result_fvs
unused_bndrs = nameSetToList (bndrs `minusNameSet` all_uses)
in
warnUnusedLocalBinds unused_bndrs `thenM_`
returnM (result, all_uses `minusNameSet` bndrs)
- -- It's important to return all the uses, not the 'real uses' used for
+ -- duUses: It's important to return all the uses, not the 'real uses' used for
-- warning about unused bindings. Otherwise consider:
-- x = 3
- -- y = let p = x in 'x'
+ -- y = let p = x in 'x' -- NB: p not used
-- If we don't "see" the dependency of 'y' on 'x', we may put the
-- bindings in the wrong order, and the type checker will complain
-- that x isn't in scope
-- Warn about missing signatures,
-- but only at top level, and not in interface mode
-- (The latter is important when renaming bindings from 'deriving' clauses.)
- getModeRn `thenM` \ mode ->
doptM Opt_WarnMissingSigs `thenM` \ warn_missing_sigs ->
(if isTopLevel top_lvl &&
- warn_missing_sigs &&
- not (isInterfaceMode mode)
+ warn_missing_sigs
then let
type_sig_vars = [n | Sig n _ _ <- siglist]
un_sigd_binders = filter (not . (`elem` type_sig_vars))
FunMonoBind new_name inf new_matches locn, sigs_for_me
)]
-
sigsForMe names_bound_here sigs
= foldlM check [] (filter (sigForThisGroup names_bound_here) sigs)
where
+ -- sigForThisGroup only returns signatures for
+ -- which sigName returns a Just
check sigs sig = case filter (eqHsSig sig) sigs of
[] -> returnM (sig:sigs)
- other -> dupSigDeclErr sig `thenM_`
+ other -> dupSigDeclErr sig other `thenM_`
returnM sigs
\end{code}
= extendTyVarEnvFVRn gen_tvs $
rnMatch (FunRhs sel_name) match
where
- tvs = map rdrNameOcc (extractHsTyRdrNames ty)
+ tvs = map rdrNameOcc (extractHsTyRdrTyVars ty)
gen_tvs = [tv | tv <- gen_tyvars, nameOccName tv `elem` tvs]
rn_match sel_name match = rnMatch (FunRhs sel_name) match
-- Check for (a) duplicate signatures
-- (b) signatures for things not in this group
-- Well, I can't see the check for (a)... ToDo!
- = mappM_ unknownSigErr bad_sigs
+ = mappM_ unknownSigErr (filter bad sigs)
where
- bad_sigs = filter (not . ok_sig) sigs
+ bad sig = not (ok_sig sig) &&
+ case sigName sig of
+ Just n | isUnboundName n -> False -- Don't complain about an unbound name again
+ other -> True
-- We use lookupSigOccRn in the signatures, which is a little bit unsatisfactory
-- because this won't work for:
-- Remove fixity sigs which have been dealt with already
renameSig :: Sig RdrName -> RnM (Sig Name)
--- ClassOpSig, FixitSig is renamed elsewhere.
+-- FixitSig is renamed elsewhere.
renameSig (Sig v ty src_loc)
= addSrcLoc src_loc $
lookupSigOccRn v `thenM` \ new_v ->
%************************************************************************
\begin{code}
-dupSigDeclErr sig
+dupSigDeclErr sig sigs
= addSrcLoc loc $
- addErr (sep [ptext SLIT("Duplicate") <+> what_it_is <> colon,
- ppr sig])
+ addErr (vcat [ptext SLIT("Duplicate") <+> what_it_is <> colon,
+ nest 2 (vcat (map ppr_sig (sig:sigs)))])
where
(what_it_is, loc) = hsSigDoc sig
+ ppr_sig sig = ppr (sigLoc sig) <> colon <+> ppr sig
unknownSigErr sig
= addSrcLoc loc $