@@ -1,6 +1,7 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2module Reporting.Error.Type where
2module Reporting.Error.Type where
4+import qualified Data.Char as Char
4import Text.PrettyPrint ((<+>))
5import Text.PrettyPrint ((<+>))
5import qualified Text.PrettyPrint as P
6import qualified Text.PrettyPrint as P
@@ -44,8 +45,9 @@ data Hint
44 | BinopLeft Var.Canonical Region.Region
45 | BinopLeft Var.Canonical Region.Region
45 | BinopRight Var.Canonical Region.Region
46 | BinopRight Var.Canonical Region.Region
46 | Binop Var.Canonical
47 | Binop Var.Canonical
47− | BadArgument Region.Region
48+ | Function (Maybe Var.Canonical)
48− | ExtraArgument Region.Region
49+ | UnexpectedArg (Maybe Var.Canonical) Int Region.Region
50+ | FunctionArity (Maybe Var.Canonical) Int Region.Region
49 | BadTypeAnnotation String
51 | BadTypeAnnotation String
50 | Instance String
52 | Instance String
51 | Literal String
53 | Literal String
@@ -53,7 +55,6 @@ data Hint
@@ -116,7 +117,7 @@ hintToString hint =
116 CaseBranch branchNumber region ->
117 CaseBranch branchNumber region ->
117 ( Just region
118 ( Just region
118 , "The branches of this case-expression return different types of values.\n\n"
119 , "The branches of this case-expression return different types of values.\n\n"
119− ++ "I noticed the mismatch in branch #" ++ show branchNumber ++ ", but go through and make sure every\n"
120+ ++ "I noticed the mismatch in the " ++ ordinalize branchNumber ++ " branch, but go through and make sure every\n"
120 ++ "branch returns the same type of value."
121 ++ "branch returns the same type of value."
@@ -135,7 +136,7 @@ hintToString hint =
135 MultiIfBranch branchNumber region ->
136 MultiIfBranch branchNumber region ->
136 ( Just region
137 ( Just region
137 , "The branches of this if-expression return different types of values.\n\n"
138 , "The branches of this if-expression return different types of values.\n\n"
138− ++ "I noticed the mismatch in branch #" ++ show branchNumber ++ ", but go through and make sure every\n"
139+ ++ "I noticed the mismatch in the " ++ ordinalize branchNumber ++ " branch, but go through and make sure every\n"
139 ++ "branch returns the same type of value."
140 ++ "branch returns the same type of value."
@@ -148,7 +149,7 @@ hintToString hint =
148 ListElement elementNumber region ->
149 ListElement elementNumber region ->
149 ( Just region
150 ( Just region
150 , "Not all elements of this list are the same type of value.\n\n"
151 , "Not all elements of this list are the same type of value.\n\n"
151− ++ "I noticed the mismatch in element #" ++ show elementNumber ++ ", but go through and make sure every\n"
152+ ++ "I noticed the mismatch in the " ++ ordinalize elementNumber ++ " element, but go through and make sure every\n"
152 ++ "element is the same type of value."
153 ++ "element is the same type of value."
@@ -174,15 +175,21 @@ hintToString hint =
174 ++ "does not match how it is used elsewhere."
175 ++ "does not match how it is used elsewhere."
177− BadArgument region ->
178+ Function maybeName ->
180+ , "The return type of " ++ funcName maybeName ++ " is being used in unexpected ways."
183+ UnexpectedArg maybeName index region ->
178 ( Just region
184 ( Just region
179− , "This argument is causing a type mismatch."
185+ , "The " ++ ordinalize index ++ " argument to " ++ funcName maybeName
186+ ++ " has an unexpected type."
182− ExtraArgument region ->
189+ FunctionArity maybeName index region ->
183 ( Just region
190 ( Just region
184− , "This expression is mistakenly being used as a function.\n"
191+ , capitalize (funcName maybeName) ++ " is not expecting a "
185− ++ "Maybe you provided an extra argument?"
192+ ++ ordinalize index ++ " argument."
188 BadTypeAnnotation name ->
195 BadTypeAnnotation name ->
@@ -228,11 +235,6 @@ hintToString hint =
228 , "This anonymous function is being used in an unexpected way."
235 , "This anonymous function is being used in an unexpected way."
233− , "The result of this function application is being used in an unexpected way."
236 Record ->
238 Record ->
237 ( Nothing
239 ( Nothing
238 , "This record is being used in an unexpected way."
240 , "This record is being used in an unexpected way."
@@ -244,3 +246,40 @@ prettyOperator (Var.Canonical _ opName) =
244 if Help.isOp opName
246 if Help.isOp opName
245 then "(" ++ opName ++ ")"
247 then "(" ++ opName ++ ")"
246 else "`" ++ opName ++ "`"
248 else "`" ++ opName ++ "`"
251+funcName :: Maybe Var.Canonical -> String
258+ "function " ++ prettyOperator var
261+capitalize :: String -> String
269+ordinalize :: Int -> String
279+ | remainder100 `elem` [11..13] = "th"
280+ | remainder10 == 1 = "st"
281+ | remainder10 == 2 = "nd"
282+ | remainder10 == 3 = "rd"
285+ show number ++ ending