-addShortErrLocLine :: SrcLoc -> Message -> ErrMsg
-addErrLocHdrLine :: SrcLoc -> Message -> Message -> ErrMsg
-addShortWarnLocLine :: SrcLoc -> Message -> WarnMsg
-
-addShortErrLocLine locn rest_of_err_msg
- = ( locn
- , hang (ppr locn <> colon)
- 4 rest_of_err_msg
- )
-
-addErrLocHdrLine locn hdr rest_of_err_msg
- = ( locn
- , hang (ppr locn <> colon<+> hdr)
- 4 rest_of_err_msg
- )
-
-addShortWarnLocLine locn rest_of_err_msg
- = ( locn
- , hang (ppr locn <> colon)
- 4 (ptext SLIT("Warning:") <+> rest_of_err_msg)
- )
-
-dontAddErrLoc :: String -> Message -> ErrMsg
-dontAddErrLoc title rest_of_err_msg
- | null title = (noSrcLoc, rest_of_err_msg)
- | otherwise =
- ( noSrcLoc, hang (text title <> colon) 4 rest_of_err_msg )
-
-printErrorsAndWarnings :: Bag ErrMsg -> Bag WarnMsg -> IO ()
+addShortErrLocLine :: SrcLoc -> PrintUnqualified -> Message -> ErrMsg
+addShortWarnLocLine :: SrcLoc -> PrintUnqualified -> Message -> WarnMsg
+ -- Used heavily by renamer/typechecker
+ -- Be refined about qualification, return an ErrMsg
+
+addErrLocHdrLine :: SrcLoc -> Message -> Message -> Message
+addWarnLocHdrLine :: SrcLoc -> Message -> Message -> Message
+ -- Used by Lint and other system stuff
+ -- Always print qualified, return a Message
+
+addShortErrLocLine locn print_unqual msg
+ = (locn, doc (mkErrStyle print_unqual))
+ where
+ doc = mkErrDoc locn msg
+
+addShortWarnLocLine locn print_unqual msg
+ = (locn, doc (mkErrStyle print_unqual))
+ where
+ doc = mkWarnDoc locn msg
+
+addErrLocHdrLine locn hdr msg
+ = mkErrDoc locn (hdr $$ msg)
+
+addWarnLocHdrLine locn hdr msg
+ = mkWarnDoc locn (hdr $$ msg)
+
+dontAddErrLoc :: Message -> ErrMsg
+dontAddErrLoc msg = (noSrcLoc, msg defaultErrStyle)
+
+mkErrDoc locn msg
+ | isGoodSrcLoc locn = hang (ppr locn <> colon) 4 msg
+ | otherwise = msg
+
+mkWarnDoc locn msg
+ | isGoodSrcLoc locn = hang (ppr locn <> colon) 4 warn_msg
+ | otherwise = warn_msg
+ where
+ warn_msg = ptext SLIT("Warning:") <+> msg
+\end{code}
+
+\begin{code}
+printError :: String -> IO ()
+printError str = hPutStrLn stderr str
+\end{code}
+
+\begin{code}
+type Messages = (Bag WarnMsg, Bag ErrMsg)
+
+emptyMessages :: Messages
+emptyMessages = (emptyBag, emptyBag)
+
+errorsFound :: DynFlags -> Messages -> Bool
+-- The dyn-flags are used to see if the user has specified
+-- -Werorr, which says that warnings should be fatal
+errorsFound dflags (warns, errs)
+ | dopt Opt_WarnIsError dflags = not (isEmptyBag errs) || not (isEmptyBag warns)
+ | otherwise = not (isEmptyBag errs)
+
+printErrorsAndWarnings :: Messages -> IO ()