@@ -23,8 +23,10 @@ data Error
23 | DuplicateValueDeclaration String
23 | DuplicateValueDeclaration String
24 | DuplicateTypeDeclaration String
24 | DuplicateTypeDeclaration String
25 | DuplicateDefinition String
25 | DuplicateDefinition String
26− | UnboundTypeVarsInAlias String [String] String [String]
27− | UnboundTypeVarsInUnion String [String] String [String]
26+ | UnboundTypeVarsInUnion String [String] [String]
27+ | UnboundTypeVarsInAlias String [String] [String]
28+ | UnusedTypeVarsInAlias String [String] [String]
29+ | MessyTypeVarsInAlias String [String] [String] [String]
30-- TO REPORT
32-- TO REPORT
@@ -148,27 +150,59 @@ toReport _localizer err =
148 ++ "`, and give each of them a unique name."
150 ++ "`, and give each of them a unique name."
151− UnboundTypeVarsInAlias typeName givenVars tvar tvars ->
153+ UnboundTypeVarsInUnion typeName givenVars unbound ->
152− unboundTypeVars "type alias" typeName givenVars tvar tvars
154+ unboundTypeVars "type" typeName givenVars unbound
154− UnboundTypeVarsInUnion typeName givenVars tvar tvars ->
156+ UnboundTypeVarsInAlias typeName givenVars unbound ->
155− unboundTypeVars "type" typeName givenVars tvar tvars
157+ unboundTypeVars "type alias" typeName givenVars unbound
159+ UnusedTypeVarsInAlias typeName givenVars unused ->
161+ "UNUSED TYPE VARIABLES"
163+ ( "Type alias `" ++ typeName ++ "` cannot have unused type variables: "
164+ ++ Help.commaSep unused
167+ [ text "You probably need to change the declaration like this:"
168+ , dullyellow $ hsep $
169+ map text ("type" : "alias" : typeName : filter (`notElem` unused) givenVars ++ ["=", "…"])
173+ MessyTypeVarsInAlias typeName givenVars unused unbound ->
175+ "TYPE VARIABLE PROBLEMS"
177+ ( "Type alias `" ++ typeName ++ "` has some problems with type variables."
180+ [ Help.reflowParagraph $
181+ "The declaration says it uses certain type variables ("
182+ ++ Help.commaSep unused ++ ") but they do not appear in the aliased type. "
183+ ++ "Furthermore, the aliased type says it uses type variables ("
184+ ++ Help.commaSep unbound
185+ ++ ") that do not appear in the declaration."
186+ , text "You probably need to change the declaration like this:"
187+ , dullyellow $ hsep $
188+ map text ("type" : "alias" : typeName : filter (`notElem` unused) givenVars ++ unbound ++ ["=", "…"])
159−unboundTypeVars :: String -> String -> [String] -> String -> [String] -> Report.Report
193+unboundTypeVars :: String -> String -> [String] -> [String] -> Report.Report
160−unboundTypeVars declKind typeName givenVars tvar tvars =
194+unboundTypeVars declKind typeName givenVars unboundVars@(tvar:_) =
161 Report.report
195 Report.report
162 "UNBOUND TYPE VARIABLES"
196 "UNBOUND TYPE VARIABLES"
164 ( Help.capitalize declKind ++ " `" ++ typeName ++ "` must declare its use of type variable"
198 ( Help.capitalize declKind ++ " `" ++ typeName ++ "` must declare its use of type variable"
165− ++ Help.commaSep (tvar:tvars)
199+ ++ Help.commaSep unboundVars
167 ( Help.stack
201 ( Help.stack
168 [ text "You probably need to change the declaration like this:"
202 [ text "You probably need to change the declaration like this:"
170 map text (declKind : typeName : givenVars)
204 map text (declKind : typeName : givenVars)
171− ++ map (dullyellow . text) (tvar : tvars)
205+ ++ map (dullyellow . text) unboundVars
172 ++ map text ["=", "…"]
206 ++ map text ["=", "…"]
173 , Help.reflowParagraph $
207 , Help.reflowParagraph $
174 "Here's why. Imagine one `" ++ typeName ++ "` where `" ++ tvar ++ "` is an Int and\
208 "Here's why. Imagine one `" ++ typeName ++ "` where `" ++ tvar ++ "` is an Int and\