on master help sign in
Simplify type error messages
c1d5f86Evan Czaplicki
compiler/Type/State.hs+3−7
@@ -47,15 +47,11 @@ modifyPool f = modify $ \state -> state { sPool = f (sPool state) }
47addError message t1 t2 =
47addError message t1 t2 =
48 modify $ \state -> state { sErrors = err : sErrors state }
48 modify $ \state -> state { sErrors = err : sErrors state }
49 where
49 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) ' '
54 err = makeError <$> extraPretty t1 <*> extraPretty t2
50 err = makeError <$> extraPretty t1 <*> extraPretty t2
55 makeError pt1 pt2 =
51 makeError pt1 pt2 =
56− P.vcat [ P.text $ "Type error" ++ spaces ++ "line ???"
52+ P.vcat [ P.text $ "Type error on line ???"
57− , P.text (List.replicate width '-')
53+ , if null message then empty else P.fsep . map P.text $ words message
58− , msg <> P.text "\n"
54+ , P.text " "
59 , P.text " Expected Type:" <+> pt1
55 , P.text " Expected Type:" <+> pt1
60 , P.text " Actual Type:" <+> pt2 <> P.text "\n"
56 , P.text " Actual Type:" <+> pt2 <> P.text "\n"
61 ]
57 ]
compiler/Type/Unify.hs+2−2
@@ -95,7 +95,7 @@ actuallyUnify variable1 variable2 = do
95 | name `elem` ["Int","Float","Char"] -> flexAndUnify variable2
95 | name `elem` ["Int","Float","Char"] -> flexAndUnify variable2
96 | otherwise -> TS.addError "Expecting something comparable (Int, Float, Char, [comparable])." variable1 variable2
96 | otherwise -> TS.addError "Expecting something comparable (Int, Float, Char, [comparable])." variable1 variable2
97
97
98− _ -> TS.addError "The following types are not equal" variable1 variable2
98+ _ -> TS.addError "" variable1 variable2
99
99
100 case (structure desc1, structure desc2) of
100 case (structure desc1, structure desc2) of
101 (Nothing, Nothing) | flex desc1 == Flexible && flex desc1 == Flexible -> merge
101 (Nothing, Nothing) | flex desc1 == Flexible && flex desc1 == Flexible -> merge
@@ -144,5 +144,5 @@ actuallyUnify variable1 variable2 = do
144 eat (x:xs) (y:ys) = eat xs ys
144 eat (x:xs) (y:ys) = eat xs ys
145 eat xs ys = xs
145 eat xs ys = xs
146
146
147− _ -> TS.addError "The following types are not equal" variable1 variable2
147+ _ -> TS.addError "" variable1 variable2
148
148