on master help sign in
Make error messages prettier
commit3c05f538d09c09904d2cc7b7d3e375bd2de42f43 authorEvan Czaplicki <info@elm-lang.org> dateSat 3 Aug 2013, 12:28 (13 years ago) parentcb1a7a2
1 file changed+14−10
compiler/Type/State.hs+14−10
compiler/Type/State.hs+14−10
@@ -49,19 +49,23 @@ addError span message t1 t2 =
4949 where
5050 err = makeError <$> extraPretty t1 <*> extraPretty t2
5151
52− location =
53− case span of
54− NoSpan msg -> if null msg then "" else ":\n\n " ++ msg
55− Span p1 p2 msg -> lineNum ++ expr
56− where
57− lineNum = if line p1 == line p2 then "on line " ++ show (line p1)
58− else "between lines " ++ show (line p1) ++ " and " ++ show (line p2)
59− expr = if null msg then "" else ":\n\n " ++ msg
52+ location = case span of
53+ NoSpan msg -> ""
54+ Span p1 p2 msg ->
55+ if line p1 == line p2 then " on line " ++ show (line p1)
56+ else " between lines " ++ show (line p1) ++ " and " ++ show (line p2)
57+
58+ display msg = if null msg then "\n"
59+ else "\n" ++ unlines (map (" "++) $ lines msg)
60+
61+ src = case span of
62+ NoSpan msg -> display msg
63+ Span _ _ msg -> display msg
6064
6165 makeError pt1 pt2 =
62− P.vcat [ P.text $ "Type error " ++ location
66+ P.vcat [ P.text $ "Type error" ++ location ++ ":"
6367 , if null message then empty else P.vcat . map P.text $ lines message
64− , P.text " "
68+ , P.text src
6569 , P.text " Expected Type:" <+> pt1
6670 , P.text " Actual Type:" <+> pt2 <> P.text "\n"
6771 ]