Commit b35e7e21 authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Sort instances by location before printing them

Reduces wobble in error messages, and is better for the programmer
parent 24746fe7
......@@ -24,12 +24,11 @@ import TyCon
import DynFlags
import Name
import Module
import SrcLoc
import Outputable
import UniqFM
import VarSet
import FastString
import Util( filterOut )
import Util( filterOut, sortWith )
import Maybes
import Control.Monad
import Data.Map (Map)
......@@ -308,15 +307,18 @@ checkForConflicts inst_envs fam_inst
conflictInstErr :: FamInst -> FamInst -> TcRn ()
conflictInstErr famInst conflictingFamInst
= addFamInstLoc famInst $
addErr (hang (ptext (sLit "Conflicting family instance declarations:"))
2 (pprFamInsts [famInst, conflictingFamInst]))
addFamInstLoc :: FamInst -> TcRn a -> TcRn a
addFamInstLoc famInst thing_inside
= setSrcSpan (mkSrcSpan loc loc) thing_inside
where
loc = getSrcLoc famInst
= addFamInstsErr (ptext (sLit "Conflicting family instance declarations:"))
[famInst, conflictingFamInst]
addFamInstsErr :: SDoc -> [FamInst] -> TcRn ()
addFamInstsErr herald insts
= setSrcSpan (getSrcSpan (head sorted)) $
addErr (hang herald 2 (pprFamInsts sorted))
where
sorted = sortWith getSrcLoc insts
-- The sortWith just arranges that instances are dislayed in order
-- of source location, which reduced wobbling in error messages,
-- and is better for users
tcGetFamInstEnvs :: TcM FamInstEnvs
-- Gets both the external-package inst-env
......
......@@ -474,25 +474,28 @@ traceDFuns ispecs
funDepErr :: ClsInst -> [ClsInst] -> TcRn ()
funDepErr ispec ispecs
= addDictLoc ispec $
addErr (hang (ptext (sLit "Functional dependencies conflict between instance declarations:"))
2 (pprInstances (ispec:ispecs)))
= addClsInstsErr (ptext (sLit "Functional dependencies conflict between instance declarations:"))
(ispec : ispecs)
dupInstErr :: ClsInst -> ClsInst -> TcRn ()
dupInstErr ispec dup_ispec
= addDictLoc ispec $
addErr (hang (ptext (sLit "Duplicate instance declarations:"))
2 (pprInstances [ispec, dup_ispec]))
= addClsInstsErr (ptext (sLit "Duplicate instance declarations:"))
[ispec, dup_ispec]
overlappingInstErr :: ClsInst -> ClsInst -> TcRn ()
overlappingInstErr ispec dup_ispec
= addDictLoc ispec $
addErr (hang (ptext (sLit "Overlapping instance declarations:"))
2 (pprInstances [ispec, dup_ispec]))
addDictLoc :: ClsInst -> TcRn a -> TcRn a
addDictLoc ispec thing_inside
= setSrcSpan (mkSrcSpan loc loc) thing_inside
where
loc = getSrcLoc ispec
= addClsInstsErr (ptext (sLit "Overlapping instance declarations:"))
[ispec, dup_ispec]
addClsInstsErr :: SDoc -> [ClsInst] -> TcRn ()
addClsInstsErr herald ispecs
= setSrcSpan (getSrcSpan (head sorted)) $
addErr (hang herald 2 (pprInstances sorted))
where
sorted = sortWith getSrcLoc ispecs
-- The sortWith just arranges that instances are dislayed in order
-- of source location, which reduced wobbling in error messages,
-- and is better for users
\end{code}
%************************************************************************
......
......@@ -34,7 +34,6 @@ import BasicTypes
import UniqFM
import Id
import FastString
import Data.Data ( Data, Typeable )
import Data.Maybe ( isJust, isNothing )
\end{code}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment