-type Error = PprStyle -> Pretty
-
-addErrLoc :: SrcLoc -> String -> Error -> Error
-addErrLoc locn title rest_of_err_msg sty
- = ppHang (ppBesides [ppr PprForUser locn,
- if null title then ppNil else ppStr (": " ++ title),
- ppChar ':'])
- 4 (rest_of_err_msg sty)
-
-addShortErrLocLine :: SrcLoc -> Error -> Error
-addShortErrLocLine locn rest_of_err_msg sty
- = ppHang (ppBeside (ppr PprForUser locn) (ppChar ':'))
- 4 (rest_of_err_msg sty)
-
-dontAddErrLoc :: String -> Error -> Error
-dontAddErrLoc title rest_of_err_msg sty
- = ppHang (ppBesides [ppStr title, ppChar ':'])
- 4 (rest_of_err_msg sty)
-
-pprBagOfErrors :: PprStyle -> Bag Error -> Pretty
-pprBagOfErrors sty bag_of_errors
- = let pretties = map ( \ e -> e sty ) (bagToList bag_of_errors) in
- ppAboves (map (\ p -> ppAbove ppSP p) pretties)
+type MsgWithLoc = (SrcLoc, Pretty.Doc)
+ -- The SrcLoc is used for sorting errors into line-number order
+ -- NB Pretty.Doc not SDoc: we deal with the printing style (in ptic
+ -- whether to qualify an External Name) at the error occurrence
+
+type ErrMsg = MsgWithLoc
+type WarnMsg = MsgWithLoc
+type Message = SDoc
+
+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