From c1d5f86e824145b0d9f6a81e1587504c19a4377b Mon Sep 17 00:00:00 2001 From: Evan Czaplicki Date: Fri, 26 Jul 2013 21:18:44 +0200 Subject: [PATCH] Simplify type error messages --- compiler/Type/State.hs | 10 +++------- compiler/Type/Unify.hs | 4 ++-- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/compiler/Type/State.hs b/compiler/Type/State.hs index e1bd0b9..3a920e6 100644 --- a/compiler/Type/State.hs +++ b/compiler/Type/State.hs @@ -47,15 +47,11 @@ modifyPool f = modify $ \state -> state { sPool = f (sPool state) } addError message t1 t2 = modify $ \state -> state { sErrors = err : sErrors state } where - wordify = P.fsep . map P.text . words - msg = wordify message - width = maximum . map length . lines $ render msg - spaces = List.replicate (width - 15 - 3) ' ' err = makeError <$> extraPretty t1 <*> extraPretty t2 makeError pt1 pt2 = - P.vcat [ P.text $ "Type error" ++ spaces ++ "line ???" - , P.text (List.replicate width '-') - , msg <> P.text "\n" + P.vcat [ P.text $ "Type error on line ???" + , if null message then empty else P.fsep . map P.text $ words message + , P.text " " , P.text " Expected Type:" <+> pt1 , P.text " Actual Type:" <+> pt2 <> P.text "\n" ] diff --git a/compiler/Type/Unify.hs b/compiler/Type/Unify.hs index bcce02b..18b18c2 100644 --- a/compiler/Type/Unify.hs +++ b/compiler/Type/Unify.hs @@ -95,7 +95,7 @@ actuallyUnify variable1 variable2 = do | name `elem` ["Int","Float","Char"] -> flexAndUnify variable2 | otherwise -> TS.addError "Expecting something comparable (Int, Float, Char, [comparable])." variable1 variable2 - _ -> TS.addError "The following types are not equal" variable1 variable2 + _ -> TS.addError "" variable1 variable2 case (structure desc1, structure desc2) of (Nothing, Nothing) | flex desc1 == Flexible && flex desc1 == Flexible -> merge @@ -144,5 +144,5 @@ actuallyUnify variable1 variable2 = do eat (x:xs) (y:ys) = eat xs ys eat xs ys = xs - _ -> TS.addError "The following types are not equal" variable1 variable2 + _ -> TS.addError "" variable1 variable2