Simplify type error messages
This commit is contained in:
parent
42065eb075
commit
c1d5f86e82
2 changed files with 5 additions and 9 deletions
|
@ -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"
|
||||
]
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue