Simplify type error messages

This commit is contained in:
Evan Czaplicki 2013-07-26 21:18:44 +02:00
parent 42065eb075
commit c1d5f86e82
2 changed files with 5 additions and 9 deletions

View file

@ -47,15 +47,11 @@ modifyPool f = modify $ \state -> state { sPool = f (sPool state) }
addError message t1 t2 = addError message t1 t2 =
modify $ \state -> state { sErrors = err : sErrors state } modify $ \state -> state { sErrors = err : sErrors state }
where 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 err = makeError <$> extraPretty t1 <*> extraPretty t2
makeError pt1 pt2 = makeError pt1 pt2 =
P.vcat [ P.text $ "Type error" ++ spaces ++ "line ???" P.vcat [ P.text $ "Type error on line ???"
, P.text (List.replicate width '-') , if null message then empty else P.fsep . map P.text $ words message
, msg <> P.text "\n" , P.text " "
, P.text " Expected Type:" <+> pt1 , P.text " Expected Type:" <+> pt1
, P.text " Actual Type:" <+> pt2 <> P.text "\n" , P.text " Actual Type:" <+> pt2 <> P.text "\n"
] ]

View file

@ -95,7 +95,7 @@ actuallyUnify variable1 variable2 = do
| name `elem` ["Int","Float","Char"] -> flexAndUnify variable2 | name `elem` ["Int","Float","Char"] -> flexAndUnify variable2
| otherwise -> TS.addError "Expecting something comparable (Int, Float, Char, [comparable])." variable1 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 case (structure desc1, structure desc2) of
(Nothing, Nothing) | flex desc1 == Flexible && flex desc1 == Flexible -> merge (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 (x:xs) (y:ys) = eat xs ys
eat xs ys = xs eat xs ys = xs
_ -> TS.addError "The following types are not equal" variable1 variable2 _ -> TS.addError "" variable1 variable2