[commit: ghc] master: Further improve the "same-occurrence" error messages (Trac #8278) (322b48b)

git at git.haskell.org git at git.haskell.org
Fri Jan 10 08:52:14 UTC 2014


Repository : ssh://git@git.haskell.org/ghc

On branch  : master
Link       : http://ghc.haskell.org/trac/ghc/changeset/322b48b92b93e1250b360d21873fa9f31c142403/ghc

>---------------------------------------------------------------

commit 322b48b92b93e1250b360d21873fa9f31c142403
Author: Simon Peyton Jones <simonpj at microsoft.com>
Date:   Thu Jan 9 16:55:31 2014 +0000

    Further improve the "same-occurrence" error messages (Trac #8278)
    
    Sometimes we actually have a good SrcSpan for the type constructor
    and reporting that is better than just reporting which module it
    was defined on


>---------------------------------------------------------------

322b48b92b93e1250b360d21873fa9f31c142403
 compiler/typecheck/TcErrors.lhs |   13 ++++++++++++-
 1 file changed, 12 insertions(+), 1 deletion(-)

diff --git a/compiler/typecheck/TcErrors.lhs b/compiler/typecheck/TcErrors.lhs
index a28a9f5..f105cdd 100644
--- a/compiler/typecheck/TcErrors.lhs
+++ b/compiler/typecheck/TcErrors.lhs
@@ -858,7 +858,8 @@ misMatchMsg oriented ty1 ty2
         , sameOccExtra ty2 ty1 ]
   | otherwise
   = sep [ ptext (sLit "Couldn't match") <+> what <+> quotes (ppr ty1)
-        , nest 14 $ ptext (sLit "with") <+> quotes (ppr ty2) ]
+        , nest 14 $ ptext (sLit "with") <+> quotes (ppr ty2)
+        , sameOccExtra ty1 ty2 ]
   where
     what | isKind ty1 = ptext (sLit "kind")
          | otherwise  = ptext (sLit "type")
@@ -876,6 +877,7 @@ mkExpectedActualMsg ty1 ty2 (TypeEqOrigin { uo_actual = act, uo_expected = exp }
 mkExpectedActualMsg _ _ _ = panic "mkExprectedAcutalMsg"
 
 sameOccExtra :: TcType -> TcType -> SDoc
+-- See Note [Disambiguating (X ~ X) errors]
 sameOccExtra ty1 ty2
   | Just (tc1, _) <- tcSplitTyConApp_maybe ty1
   , Just (tc2, _) <- tcSplitTyConApp_maybe ty2
@@ -890,6 +892,10 @@ sameOccExtra ty1 ty2
   = empty
   where
     ppr_from same_pkg nm
+      | isGoodSrcSpan loc
+      = hang (quotes (ppr nm) <+> ptext (sLit "is defined at"))
+           2 (ppr loc)
+      | otherwise  -- Imported things have an UnhelpfulSrcSpan
       = hang (quotes (ppr nm))
            2 (sep [ ptext (sLit "is defined in") <+> quotes (ppr (moduleName mod))
                   , ppUnless (same_pkg || pkg == mainPackageId) $
@@ -897,8 +903,13 @@ sameOccExtra ty1 ty2
        where
          pkg = modulePackageId mod
          mod = nameModule nm
+         loc = nameSrcSpan nm
 \end{code}
 
+Note [Disambiguating (X ~ X) errors]
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+See Trac #8278
+
 Note [Reporting occurs-check errors]
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 Given (a ~ [a]), if 'a' is a rigid type variable bound by a user-supplied



More information about the ghc-commits mailing list