on master help sign in
Simplify type error messages
commitc1d5f86e824145b0d9f6a81e1587504c19a4377b authorEvan Czaplicki <info@elm-lang.org> dateFri 26 Jul 2013, 21:18 (13 years ago) parent42065eb
2 files changed+5−9
compiler/Type/State.hs+3−7 compiler/Type/Unify.hs+2−2
compiler/Type/State.hs+3−7
@@ -47,15 +47,11 @@ modifyPool f = modify $ \state -> state { sPool = f (sPool state) }
4747addError message t1 t2 =
4848 modify $ \state -> state { sErrors = err : sErrors state }
4949 where
50− wordify = P.fsep . map P.text . words
51− msg = wordify message
52− width = maximum . map length . lines $ render msg
53− spaces = List.replicate (width - 15 - 3) ' '
5450 err = makeError <$> extraPretty t1 <*> extraPretty t2
5551 makeError pt1 pt2 =
56− P.vcat [ P.text $ "Type error" ++ spaces ++ "line ???"
57− , P.text (List.replicate width '-')
58− , msg <> P.text "\n"
52+ P.vcat [ P.text $ "Type error on line ???"
53+ , if null message then empty else P.fsep . map P.text $ words message
54+ , P.text " "
5955 , P.text " Expected Type:" <+> pt1
6056 , P.text " Actual Type:" <+> pt2 <> P.text "\n"
6157 ]
compiler/Type/Unify.hs+2−2
@@ -95,7 +95,7 @@ actuallyUnify variable1 variable2 = do
9595 | name `elem` ["Int","Float","Char"] -> flexAndUnify variable2
9696 | otherwise -> TS.addError "Expecting something comparable (Int, Float, Char, [comparable])." variable1 variable2
9797
98− _ -> TS.addError "The following types are not equal" variable1 variable2
98+ _ -> TS.addError "" variable1 variable2
9999
100100 case (structure desc1, structure desc2) of
101101 (Nothing, Nothing) | flex desc1 == Flexible && flex desc1 == Flexible -> merge
@@ -144,5 +144,5 @@ actuallyUnify variable1 variable2 = do
144144 eat (x:xs) (y:ys) = eat xs ys
145145 eat xs ys = xs
146146
147− _ -> TS.addError "The following types are not equal" variable1 variable2
147+ _ -> TS.addError "" variable1 variable2
148148