+
%
% (c) The University of Glasgow 2006
% (c) The GRASP/AQUA Project, Glasgow University, 1993-1998
-- The above warning supression flag is a temporary kludge.
-- While working on this module you are encouraged to remove it and fix
-- any warnings in the module. See
--- http://hackage.haskell.org/trac/ghc/wiki/CodingStyle#Warnings
+-- http://hackage.haskell.org/trac/ghc/wiki/Commentary/CodingStyle#Warnings
-- for details
module CoreLint (
import TyCon
import BasicTypes
import StaticFlags
+import ListSetOps
import DynFlags
import Outputable
-
-#ifdef DEBUG
-import Util ( notNull )
-#endif
-
+import Util
import Data.Maybe
\end{code}
-- Put all the top-level binders in scope at the start
-- This is because transformation rules can bring something
-- into use 'unexpectedly'
- lint_binds binds = addInScopeVars (bindersOfBinds binds) $
+ lint_binds binds = addLoc TopLevelBindings $
+ addInScopeVars (bindersOfBinds binds) $
mapM lint_bind binds
lint_bind (Rec prs) = mapM_ (lintSingleBinding TopLevel Recursive) prs
else lintAndScopeId var
; scope $ \_ ->
do { -- Check the alternatives
- checkCaseAlts e scrut_ty alts
- ; mapM (lintCoreAlt scrut_ty alt_ty) alts
+ mapM (lintCoreAlt scrut_ty alt_ty) alts
+ ; checkCaseAlts e scrut_ty alts
; return alt_ty } }
where
pass_var f = f var
| CasePat CoreAlt -- *Pattern* of the case alternative
| AnExpr CoreExpr -- Some expression
| ImportedUnfolding SrcLoc -- Some imported unfolding (ToDo: say which)
+ | TopLevelBindings
\end{code}
LintM (\ loc subst errs -> unLintM m (extra_loc:loc) subst errs)
addInScopeVars :: [Var] -> LintM a -> LintM a
-addInScopeVars vars m =
- LintM (\ loc subst errs -> unLintM m loc (extendTvInScope subst vars) errs)
+addInScopeVars vars m
+ | null dups
+ = LintM (\ loc subst errs -> unLintM m loc (extendTvInScope subst vars) errs)
+ | otherwise
+ = addErrL (dupVars dups)
+ where
+ (_, dups) = removeDups compare vars
updateTvSubst :: TvSubst -> LintM a -> LintM a
updateTvSubst subst' m =
dumpLoc (ImportedUnfolding locn)
= (locn, brackets (ptext SLIT("in an imported unfolding")))
+dumpLoc TopLevelBindings
+ = (noSrcLoc, empty)
pp_binders :: [Var] -> SDoc
pp_binders bs = sep (punctuate comma (map pp_binder bs))
ptext SLIT("Type of enclosed expr:") <+> ppr expr_ty
]
+dupVars vars
+ = hang (ptext SLIT("Duplicate variables brought into scope"))
+ 2 (ppr vars)
+
mkStrangeTyMsg e
= ptext SLIT("Type where expression expected:") <+> ppr e
\end{code}