on master help sign in
Go to original error style. I think it's nicer.
commit2874797ddb991747a40841e8a2a3964dc770e1bf authorEvan Czaplicki <info@elm-lang.org> dateThu 19 Dec 2013, 14:45 (13 years ago) parentc8854a9
3 files changed+15−25
compiler/Type/Solve.hs+3−3 compiler/Type/State.hs+7−12 compiler/Type/Unify.hs+5−10
compiler/Type/Solve.hs+3−3
@@ -174,11 +174,11 @@ allDistinct span vars = do
174174 desc <- liftIO $ UF.descriptor var
175175 case structure desc of
176176 Just _ -> TS.addError span (Just msg) var var
177− where msg = "Cannot generalize something that is not a type variable"
177+ where msg = "Cannot generalize something that is not a type variable."
178178
179179 Nothing -> do
180180 if mark desc == seen
181− then let msg = "Duplicate variable during generalization"
181+ then let msg = "Duplicate variable during generalization."
182182 in TS.addError span (Just msg) var var
183183 else return ()
184184 liftIO $ UF.setDescriptor var (desc { mark = seen })
@@ -190,5 +190,5 @@ isGeneric span var = do
190190 desc <- liftIO $ UF.descriptor var
191191 if rank desc == noRank
192192 then return ()
193− else let msg = "Unable to generalize a type variable. It is not unranked"
193+ else let msg = "Unable to generalize a type variable. It is not unranked."
194194 in TS.addError span (Just msg) var var
compiler/Type/State.hs+7−12
@@ -56,13 +56,11 @@ addError span hint t1 t2 =
5656 t1' <- prettiest <$> toSrcType t1
5757 t2' <- prettiest <$> toSrcType t2
5858 return . P.vcat $
59− [ display $ case span of { NoSpan msg -> msg ; Span _ _ msg -> msg }
60− , case hint of
61− Nothing -> P.text " Could not match the following types:"
62− Just msg -> P.text $ eightyCharLines 2 $
63− msg ++ ", so I could not match the following types:"
64− , P.text " " <> t1'
65− , P.text " " <> t2'
59+ [ P.text $ "Type error" ++ location ++ ":"
60+ , maybe P.empty P.text hint
61+ , display $ case span of { NoSpan msg -> msg ; Span _ _ msg -> msg }
62+ , P.text " Expected Type:" <+> t1'
63+ , P.text " Actual Type:" <+> t2'
6664 ]
6765
6866 location = case span of
@@ -72,11 +70,8 @@ addError span hint t1 t2 =
7270 else " between lines " ++ show (line p1) ++ " and " ++ show (line p2)
7371
7472 display msg =
75− case lines msg of
76− [] -> P.text $ "Type error" ++ location ++ ":"
77− lines' ->
78− P.vcat [ P.text $ "Type error" ++ location ++ ", in or near this expression:"
79− , P.text $ " " ++ List.intercalate "\n " lines' ]
73+ P.vcat [ P.text $ concatMap ("\n "++) (lines msg)
74+ , P.text " " ]
8075
8176
8277switchToPool pool = modifyPool (\_ -> pool)
compiler/Type/Unify.hs+5−10
@@ -80,11 +80,11 @@ actuallyUnify span variable1 variable2 = do
8080 unifyNumber svar name
8181 | name `elem` ["Int","Float","number"] = flexAndUnify svar
8282 | otherwise = TS.addError span (Just hint) variable1 variable2
83− where hint = "A number must be an Int or Float"
83+ where hint = "A number must be an Int or Float."
8484
8585 comparableError maybe =
8686 TS.addError span (Just $ Maybe.fromMaybe msg maybe) variable1 variable2
87− where msg = "A comparable must be an Int, Float, Char, String, list, or tuple"
87+ where msg = "A comparable must be an Int, Float, Char, String, list, or tuple."
8888
8989 unifyComparable var name
9090 | name `elem` ["Int","Float","Char","String","comparable"] = flexAndUnify var
@@ -98,7 +98,7 @@ actuallyUnify span variable1 variable2 = do
9898 unify' v =<< liftIO (var $ Is Comparable)
9999 Tuple vs
100100 | length vs > 6 ->
101− comparableError $ Just "Cannot compare a tuple with more than 6 elements"
101+ comparableError $ Just "Cannot compare a tuple with more than 6 elements."
102102 | otherwise ->
103103 do flexAndUnify varSuper
104104 cmpVars <- liftIO $ forM [1..length vs] $ \_ -> var (Is Comparable)
@@ -113,13 +113,8 @@ actuallyUnify span variable1 variable2 = do
113113 rigidError variable = TS.addError span (Just hint) variable1 variable2
114114 where
115115 var = "'" ++ render (pretty Never variable) ++ "'"
116− hint = concat
117− [ "This probably relates to a type annotation. A type "
118− , "annotation may say ", var, " but should be a more "
119− , "specific type. Also, type variables are not "
120− , "shared between type annotations, so ", var, " in one "
121− , "is not the same as " ++ var ++ " in another. "
122− , "Something like that happened" ]
116+ hint = "Cannot unify rigid type variable " ++ var ++
117+ ".\nThe problem probably relates to a type annotation."
123118
124119 superUnify =
125120 case (flex desc1, flex desc2, name desc1, name desc2) of