Fix Trac #3193: improve line number reporting for equality constraints
[ghc-hetmet.git] / compiler / typecheck / TcRnMonad.lhs
index 2450d7b..a8146ba 100644 (file)
@@ -74,7 +74,7 @@ initTc hsc_env hsc_src keep_rn_syntax mod do_this
        keep_var     <- newIORef emptyNameSet ;
     used_rdrnames_var <- newIORef Set.empty ;
        th_var       <- newIORef False ;
-       dfun_n_var   <- newIORef 1 ;
+       dfun_n_var   <- newIORef emptyOccSet ;
        type_env_var <- case hsc_type_env_var hsc_env of {
                            Just (_mod, te_var) -> return te_var ;
                            Nothing             -> newIORef emptyNameEnv } ;
@@ -711,11 +711,11 @@ getInstLoc origin
   = do { loc <- getSrcSpanM ; env <- getLclEnv ;
         return (InstLoc origin loc (tcl_ctxt env)) }
 
-addInstCtxt :: InstLoc -> TcM a -> TcM a
+setInstCtxt :: InstLoc -> TcM a -> TcM a
 -- Add the SrcSpan and context from the first Inst in the list
 --     (they all have similar locations)
-addInstCtxt (InstLoc _ src_loc ctxt) thing_inside
-  = setSrcSpan src_loc (updCtxt (\_ -> ctxt) thing_inside)
+setInstCtxt (InstLoc _ src_loc ctxt) thing_inside
+  = setSrcSpan src_loc (setErrCtxt ctxt thing_inside)
 \end{code}
 
     The addErrTc functions add an error message, but do not cause failure.
@@ -836,12 +836,15 @@ debugTc thing
 %************************************************************************
 
 \begin{code}
-nextDFunIndex :: TcM Int       -- Get the next dfun index
-nextDFunIndex = do { env <- getGblEnv
-                  ; let dfun_n_var = tcg_dfun_n env
-                  ; n <- readMutVar dfun_n_var
-                  ; writeMutVar dfun_n_var (n+1)
-                  ; return n }
+chooseUniqueOccTc :: (OccSet -> OccName) -> TcM OccName
+chooseUniqueOccTc fn =
+  do { env <- getGblEnv
+     ; let dfun_n_var = tcg_dfun_n env
+     ; set <- readMutVar dfun_n_var
+     ; let occ = fn set
+     ; writeMutVar dfun_n_var (extendOccSet set occ)
+     ; return occ
+     }
 
 getLIEVar :: TcM (TcRef LIE)
 getLIEVar = do { env <- getLclEnv; return (tcl_lie env) }