Show source strings in error messages when possible

This commit is contained in:
Evan Czaplicki 2013-08-03 11:41:47 -07:00
parent 51bc878b51
commit 20047ec0eb

View file

@ -51,11 +51,13 @@ addError span message t1 t2 =
location =
case span of
NoSpan -> ""
Span p1 p2 ->
if line p1 == line p2 then "on line " ++ show (line p1)
else "between lines " ++ show (line p1) ++ " and " ++ show (line p2)
NoSpan msg -> if null msg then "" else "in\n\n " ++ msg
Span p1 p2 msg -> lineNum ++ expr
where
lineNum = if line p1 == line p2 then "on line " ++ show (line p1)
else "between lines " ++ show (line p1) ++ " and " ++ show (line p2)
expr = if null msg then "" else "\n\n " ++ msg
makeError pt1 pt2 =
P.vcat [ P.text $ "Type error " ++ location
, if null message then empty else P.vcat . map P.text $ lines message