-tcPat ctxt pat exp_ty thing_inside
- = do { err_ctxt <- getErrCtxt
- ; maybeAddErrCtxt (patCtxt (unLoc pat)) $
- tc_lpat ctxt pat exp_ty $
- setErrCtxt err_ctxt thing_inside }
- -- Restore error context before doing thing_inside
- -- See note [Nesting] above
+tcPat ctxt (L span pat) exp_ty thing_inside
+ = do { -- Restore error context before doing thing_inside
+ -- See note [Nesting] above
+ err_ctxt <- getErrCtxt
+ ; let real_thing_inside = setErrCtxt err_ctxt thing_inside
+
+ -- It's OK to keep setting the SrcSpan;
+ -- it just overwrites the previous value
+ ; (pat', tvs, res) <- setSrcSpan span $
+ maybeAddErrCtxt (patCtxt pat) $
+ tc_pat ctxt pat exp_ty $
+ real_thing_inside
+
+ ; return (L span pat', tvs, res)
+ }