Commit b598d8ac authored by simonpj@microsoft.com's avatar simonpj@microsoft.com

More error message wibbles

parent 7966f851
...@@ -158,7 +158,7 @@ reportTidyWanteds ctxt unsolved ...@@ -158,7 +158,7 @@ reportTidyWanteds ctxt unsolved
reportFlat :: ReportErrCtxt -> [PredType] -> CtOrigin -> TcM () reportFlat :: ReportErrCtxt -> [PredType] -> CtOrigin -> TcM ()
reportFlat ctxt flats origin reportFlat ctxt flats origin
= do { unless (null dicts) $ reportDictErrs ctxt dicts origin = do { unless (null dicts) $ reportDictErrs ctxt dicts origin
; unless (null eqs) $ reportEqErrs ctxt eqs ; unless (null eqs) $ reportEqErrs ctxt eqs origin
; unless (null ips) $ reportIPErrs ctxt ips origin ; unless (null ips) $ reportIPErrs ctxt ips origin
; ASSERT( null others ) return () } ; ASSERT( null others ) return () }
where where
...@@ -277,12 +277,17 @@ reportIPErrs ctxt ips orig ...@@ -277,12 +277,17 @@ reportIPErrs ctxt ips orig
%************************************************************************ %************************************************************************
\begin{code} \begin{code}
reportEqErrs :: ReportErrCtxt -> [PredType] -> TcM () reportEqErrs :: ReportErrCtxt -> [PredType] -> CtOrigin -> TcM ()
reportEqErrs ctxt eqs reportEqErrs ctxt eqs orig
= mapM_ report_one eqs = mapM_ report_one eqs
where where
report_one (EqPred ty1 ty2) = reportEqErr ctxt ty1 ty2 report_one (EqPred ty1 ty2)
report_one pred = pprPanic "reportEqErrs" (ppr pred) = do { (env1, extra) <- getWantedEqExtra (cec_tidy ctxt) orig ty1 ty2
; let ctxt' = ctxt { cec_tidy = env1
, cec_extra = cec_extra ctxt $$ extra }
; reportEqErr ctxt' ty1 ty2 }
report_one pred
= pprPanic "reportEqErrs" (ppr pred)
reportEqErr :: ReportErrCtxt -> TcType -> TcType -> TcM () reportEqErr :: ReportErrCtxt -> TcType -> TcType -> TcM ()
reportEqErr ctxt ty1 ty2 reportEqErr ctxt ty1 ty2
...@@ -652,23 +657,25 @@ kindErrorTcS :: CtFlavor -> TcType -> TcType -> TcS () ...@@ -652,23 +657,25 @@ kindErrorTcS :: CtFlavor -> TcType -> TcType -> TcS ()
kindErrorTcS fl ty1 ty2 kindErrorTcS fl ty1 ty2
= wrapErrTcS $ = wrapErrTcS $
setCtFlavorLoc fl $ setCtFlavorLoc fl $
do { (env0, extra) <- getEqExtra fl ty1 ty2 do { env0 <- tcInitTidyEnv
; let (env1, ty1') = tidyOpenType env0 ty1 ; (env1, extra) <- getEqExtra env0 fl ty1 ty2
(env2, ty2') = tidyOpenType env1 ty2 ; let (env2, ty1') = tidyOpenType env1 ty1
(env3, ty2') = tidyOpenType env2 ty2
ctxt = CEC { cec_encl = [] ctxt = CEC { cec_encl = []
, cec_extra = extra , cec_extra = extra
, cec_tidy = env2 } , cec_tidy = env3 }
; reportEqErr ctxt ty1' ty2' } ; reportEqErr ctxt ty1' ty2' }
misMatchErrorTcS :: CtFlavor -> TcType -> TcType -> TcS a misMatchErrorTcS :: CtFlavor -> TcType -> TcType -> TcS a
misMatchErrorTcS fl ty1 ty2 misMatchErrorTcS fl ty1 ty2
= wrapErrTcS $ = wrapErrTcS $
setCtFlavorLoc fl $ setCtFlavorLoc fl $
do { (env0, extra) <- getEqExtra fl ty1 ty2 do { env0 <- tcInitTidyEnv
; let (env1, ty1') = tidyOpenType env0 ty1 ; let (env1, ty1') = tidyOpenType env0 ty1
(env2, ty2') = tidyOpenType env1 ty2 (env2, ty2') = tidyOpenType env1 ty2
(env3, msg) = misMatchMsgWithExtras env2 ty1' ty2' (env3, msg) = misMatchMsgWithExtras env2 ty1' ty2'
; failWithTcM (env3, inaccessible_msg $$ msg $$ extra) } ; (env4, extra) <- getEqExtra env3 fl ty1 ty2
; failWithTcM (env4, inaccessible_msg $$ msg $$ extra) }
where where
inaccessible_msg inaccessible_msg
= case fl of = case fl of
...@@ -686,11 +693,12 @@ occursCheckErrorTcS :: CtFlavor -> TcTyVar -> TcType -> TcS a ...@@ -686,11 +693,12 @@ occursCheckErrorTcS :: CtFlavor -> TcTyVar -> TcType -> TcS a
occursCheckErrorTcS fl tv ty occursCheckErrorTcS fl tv ty
= wrapErrTcS $ = wrapErrTcS $
setCtFlavorLoc fl $ setCtFlavorLoc fl $
do { (env0, extra2) <- getEqExtra fl (mkTyVarTy tv) ty do { env0 <- tcInitTidyEnv
; let (env1, tv') = tidyOpenTyVar env0 tv ; let (env1, tv') = tidyOpenTyVar env0 tv
(env2, ty') = tidyOpenType env1 ty (env2, ty') = tidyOpenType env1 ty
extra1 = sep [ppr tv', char '=', ppr ty'] extra1 = sep [ppr tv', char '=', ppr ty']
; failWithTcM (env2, hang msg 2 (extra1 $$ extra2)) } ; (env3, extra2) <- getEqExtra env2 fl (mkTyVarTy tv) ty
; failWithTcM (env3, hang msg 2 (extra1 $$ extra2)) }
where where
msg = text $ "Occurs check: cannot construct the infinite type:" msg = text $ "Occurs check: cannot construct the infinite type:"
...@@ -735,21 +743,19 @@ setCtFlavorLoc (Wanted loc) thing = setCtLoc loc thing ...@@ -735,21 +743,19 @@ setCtFlavorLoc (Wanted loc) thing = setCtLoc loc thing
setCtFlavorLoc (Derived loc) thing = setCtLoc loc thing setCtFlavorLoc (Derived loc) thing = setCtLoc loc thing
setCtFlavorLoc (Given loc) thing = setCtLoc loc thing setCtFlavorLoc (Given loc) thing = setCtLoc loc thing
getEqExtra :: CtFlavor -> TcType -> TcType -> TcM (TidyEnv, SDoc) getEqExtra :: TidyEnv -> CtFlavor -> TcType -> TcType -> TcM (TidyEnv, SDoc)
getEqExtra (Wanted loc) ty1 ty2 = getWantedEqExtra (ctLocOrigin loc) ty1 ty2 getEqExtra env (Wanted loc) ty1 ty2 = getWantedEqExtra env (ctLocOrigin loc) ty1 ty2
getEqExtra (Derived loc) ty1 ty2 = getWantedEqExtra (ctLocOrigin loc) ty1 ty2 getEqExtra env (Derived loc) ty1 ty2 = getWantedEqExtra env (ctLocOrigin loc) ty1 ty2
getEqExtra (Given _) _ _ = do { env0 <- tcInitTidyEnv getEqExtra env (Given _) _ _ = return (env, empty)
; return (env0, empty) }
-- We could print more info, but it seems to be already coming out -- We could print more info, but it seems to be already coming out
getWantedEqExtra :: CtOrigin -> TcType -> TcType -> TcM (TidyEnv, SDoc) getWantedEqExtra :: TidyEnv -> CtOrigin -> TcType -> TcType -> TcM (TidyEnv, SDoc)
getWantedEqExtra (TypeEqOrigin item) ty1 ty2 getWantedEqExtra env0 (TypeEqOrigin item) ty1 ty2
-- If the types in the error message are the same -- If the types in the error message are the same
-- as the types we are unifying (remember to zonk the latter) -- as the types we are unifying (remember to zonk the latter)
-- don't add the extra expected/actual message -- don't add the extra expected/actual message
= do { act <- zonkTcType (uo_actual item) = do { act <- zonkTcType (uo_actual item)
; exp <- zonkTcType (uo_expected item) ; exp <- zonkTcType (uo_expected item)
; env0 <- tcInitTidyEnv
; if (act `tcEqType` ty1 && exp `tcEqType` ty2) ; if (act `tcEqType` ty1 && exp `tcEqType` ty2)
|| (exp `tcEqType` ty1 && act `tcEqType` ty2) || (exp `tcEqType` ty1 && act `tcEqType` ty2)
then then
...@@ -759,7 +765,6 @@ getWantedEqExtra (TypeEqOrigin item) ty1 ty2 ...@@ -759,7 +765,6 @@ getWantedEqExtra (TypeEqOrigin item) ty1 ty2
(env2, act') = tidyOpenType env1 act (env2, act') = tidyOpenType env1 act
; return (env2, mkExpectedActualMsg act' exp') } } ; return (env2, mkExpectedActualMsg act' exp') } }
getWantedEqExtra orig _ _ getWantedEqExtra env0 orig _ _
= do { env0 <- tcInitTidyEnv = return (env0, pprArising orig)
; return (env0, pprArising orig) }
\end{code} \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