on master help sign in
Go to original error style. I think it's nicer.
2874797Evan Czaplicki
compiler/Type/Solve.hs+3−3
@@ -174,11 +174,11 @@ allDistinct span vars = do
174 desc <- liftIO $ UF.descriptor var
174 desc <- liftIO $ UF.descriptor var
175 case structure desc of
175 case structure desc of
176 Just _ -> TS.addError span (Just msg) var var
176 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."
178
178
179 Nothing -> do
179 Nothing -> do
180 if mark desc == seen
180 if mark desc == seen
181− then let msg = "Duplicate variable during generalization"
181+ then let msg = "Duplicate variable during generalization."
182 in TS.addError span (Just msg) var var
182 in TS.addError span (Just msg) var var
183 else return ()
183 else return ()
184 liftIO $ UF.setDescriptor var (desc { mark = seen })
184 liftIO $ UF.setDescriptor var (desc { mark = seen })
@@ -190,5 +190,5 @@ isGeneric span var = do
190 desc <- liftIO $ UF.descriptor var
190 desc <- liftIO $ UF.descriptor var
191 if rank desc == noRank
191 if rank desc == noRank
192 then return ()
192 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."
194 in TS.addError span (Just msg) var var
194 in TS.addError span (Just msg) var var
compiler/Type/State.hs+7−12
@@ -56,13 +56,11 @@ addError span hint t1 t2 =
56 t1' <- prettiest <$> toSrcType t1
56 t1' <- prettiest <$> toSrcType t1
57 t2' <- prettiest <$> toSrcType t2
57 t2' <- prettiest <$> toSrcType t2
58 return . P.vcat $
58 return . P.vcat $
59+ [ P.text $ "Type error" ++ location ++ ":"
60+ , maybe P.empty P.text hint
59− [ display $ case span of { NoSpan msg -> msg ; Span _ _ msg -> msg }
61+ , display $ case span of { NoSpan msg -> msg ; Span _ _ msg -> msg }
60− , case hint of
62+ , P.text " Expected Type:" <+> t1'
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'
63+ , P.text " Actual Type:" <+> t2'
66 ]
64 ]
67
65
68 location = case span of
66 location = case span of
@@ -72,11 +70,8 @@ addError span hint t1 t2 =
72 else " between lines " ++ show (line p1) ++ " and " ++ show (line p2)
70 else " between lines " ++ show (line p1) ++ " and " ++ show (line p2)
73
71
74 display msg =
72 display msg =
75− case lines msg of
73+ P.vcat [ P.text $ concatMap ("\n "++) (lines msg)
76− [] -> P.text $ "Type error" ++ location ++ ":"
74+ , P.text " " ]
77− lines' ->
78− P.vcat [ P.text $ "Type error" ++ location ++ ", in or near this expression:"
79− , P.text $ " " ++ List.intercalate "\n " lines' ]
80
75
81
76
82switchToPool pool = modifyPool (\_ -> pool)
77switchToPool pool = modifyPool (\_ -> pool)
compiler/Type/Unify.hs+5−10
@@ -80,11 +80,11 @@ actuallyUnify span variable1 variable2 = do
80 unifyNumber svar name
80 unifyNumber svar name
81 | name `elem` ["Int","Float","number"] = flexAndUnify svar
81 | name `elem` ["Int","Float","number"] = flexAndUnify svar
82 | otherwise = TS.addError span (Just hint) variable1 variable2
82 | 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."
84
84
85 comparableError maybe =
85 comparableError maybe =
86 TS.addError span (Just $ Maybe.fromMaybe msg maybe) variable1 variable2
86 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."
88
88
89 unifyComparable var name
89 unifyComparable var name
90 | name `elem` ["Int","Float","Char","String","comparable"] = flexAndUnify var
90 | name `elem` ["Int","Float","Char","String","comparable"] = flexAndUnify var
@@ -98,7 +98,7 @@ actuallyUnify span variable1 variable2 = do
98 unify' v =<< liftIO (var $ Is Comparable)
98 unify' v =<< liftIO (var $ Is Comparable)
99 Tuple vs
99 Tuple vs
100 | length vs > 6 ->
100 | 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."
102 | otherwise ->
102 | otherwise ->
103 do flexAndUnify varSuper
103 do flexAndUnify varSuper
104 cmpVars <- liftIO $ forM [1..length vs] $ \_ -> var (Is Comparable)
104 cmpVars <- liftIO $ forM [1..length vs] $ \_ -> var (Is Comparable)
@@ -113,13 +113,8 @@ actuallyUnify span variable1 variable2 = do
113 rigidError variable = TS.addError span (Just hint) variable1 variable2
113 rigidError variable = TS.addError span (Just hint) variable1 variable2
114 where
114 where
115 var = "'" ++ render (pretty Never variable) ++ "'"
115 var = "'" ++ render (pretty Never variable) ++ "'"
116− hint = concat
116+ hint = "Cannot unify rigid type variable " ++ var ++
117− [ "This probably relates to a type annotation. A type "
117+ ".\nThe problem probably relates to a type annotation."
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" ]
123
118
124 superUnify =
119 superUnify =
125 case (flex desc1, flex desc2, name desc1, name desc2) of
120 case (flex desc1, flex desc2, name desc1, name desc2) of