1{-# OPTIONS_GHC -Wall #-}
2{-# LANGUAGE OverloadedStrings #-}
3module Reporting.Error.Syntax
6 , Problem(..), Theory(..)
11import qualified Data.Set as Set
12import Data.Text (Text)
14import qualified Reporting.Render.Type as RenderType
15import qualified Reporting.Region as Region
16import qualified Reporting.Report as Report
17import qualified Reporting.Helpers as Help
18import Reporting.Helpers ((<>), dullyellow, hsep, i2t, reflowParagraph, text)
32 | SettingsOnNormalModule
33 | SettingsOnPortModule
34 | DuplicateSettingOnEffectModule Text
35 | BadSettingOnEffectModule Text
36 | NoSettingsOnEffectModule
37 | MissingManagerOnEffectModule Text
40 | TypeWithoutDefinition Text
42 | DuplicateArgument Text Text
43 | DuplicateFieldName Region.Region Text
44 | DuplicateValueDeclaration Text
45 | DuplicateTypeDeclaration Text
46 | DuplicateDefinition Text
47 | UnboundTypeVarsInUnion Text [Text] [Text]
48 | UnboundTypeVarsInAlias Text [Text] [Text]
49 | UnusedTypeVarsInAlias Text [Text] [Text]
50 | MessyTypeVarsInAlias Text [Text] [Text] [Text]
58 = ParseError !Int !Int !Problem
66 | EndOfFile_MultiString
76 | BadChunkInQualifiedCapVar
101toReport :: RenderType.Localizer -> Error -> Report.Report
102toReport _localizer err =
105 problemToReport problem
107 BadFunctionName arity ->
109 "BAD FUNCTION DEFINITION"
111 "Complex patterns cannot be used as function names."
113 "This function definition has " <> i2t arity <> " arguments, but instead\
114 \ of a normal name like `add` or `reverse` it has a pattern. There is no\
115 \ way to \"deconstruct\" a function with pattern matching, so this needs to\
116 \ be changed to a normal name."
123 ("The free variable `" <> name <> "` appears more than once in this pattern.")
125 [ text "Rename the variables so there are no duplicates."
127 "In Elm, pattern matching works by binding these free variables to subsections\
128 \ of the matching value. It does not make sense to have the same name for two\
129 \ different subsections though! When you say `" <> name <> "` in some code, there\
130 \ is no way for me to know which subsection you mean!"
138 ("This documentation comment is not followed by anything.")
140 "All documentation comments need to be right above the declaration they\
141 \ describe. Maybe some code got deleted or commented out by accident? Or\
142 \ maybe this comment is here by accident?"
145 SettingsOnNormalModule ->
147 "BAD MODULE DECLARATION"
149 "A normal module can expose values, but not settings like this."
151 "If you want a normal module, just remove this stuff. If you want to create\
152 \ an `effect module` you just forgot to use the `effect` keyword. In that\
153 \ case, just change `module` to `effect module` and you should be headed in\
154 \ the right direction!"
157 SettingsOnPortModule ->
159 "BAD MODULE DECLARATION"
161 "A port module can expose values, but not have settings like this."
163 "If you want a port module, just remove this stuff. If you want to create\
164 \ a custom effect module instead (which is rare) just change `port module`\
165 \ to `effect module` and you should be headed in the right direction!"
168 DuplicateSettingOnEffectModule name ->
170 "EFFECT MODULE PROBLEM"
172 ("You have defined " <> Help.functionName name <> " multiple times.")
174 "There can only be one " <> Help.functionName name
175 <> " though! Remove until there is one left."
178 BadSettingOnEffectModule name ->
180 "EFFECT MODULE PROBLEM"
182 ("Setting " <> Help.functionName name <> " is not recognized.")
184 "Remove this entry and you should be all set!"
187 NoSettingsOnEffectModule ->
189 "EFFECT MODULE PROBLEM"
191 ("You are defining an effect module, but it has no settings.")
193 "If you just wanted a normal module, change the keywords `effect module`\
194 \ to `module` and you should be all set. If you want a proper effect module,\
195 \ you need to specify your commands and/or subscriptions. Read more about this\
196 \ here: <http://guide.elm-lang.org/effect_managers/>"
199 MissingManagerOnEffectModule name ->
201 "EFFECT MODULE PROBLEM"
203 ("You are defining an effect module, but there is no " <> Help.functionName name <> " defined.")
205 "There is a small set of top-level functions and values that must be defined\
206 \ in any complete effect module. The best thing is probably to just read more\
207 \ about effect modules here:\
208 \ <http://guide.elm-lang.org/effect_managers/>"
211 UnexpectedPort name ->
215 ("You are declaring port " <> Help.functionName name <> " in a normal module.")
217 "All ports must be defined in a `port module`. You should probably have just\
218 \ one of these for your project. This way all of your foreign interactions\
219 \ stay relatively organized."
222 TypeWithoutDefinition valueName ->
226 ("There is a type annotation for `" <> valueName <> "` but there"
227 <> " is no corresponding definition!"
230 "Directly below the type annotation, put a definition like:\n\n"
231 <> " " <> valueName <> " = 42"
234 DuplicateArgument funcName argName ->
238 ( "The name `" <> argName
239 <> "` is used more than once in the arguments of "
240 <> Help.functionName funcName <> "."
243 "Rename things until `" <> argName <> "` is used only once.\
244 \ Otherwise how can we tell which one you want when you\
245 \ say `" <> argName <> "` it in the body of your function?"
248 DuplicateFieldName region name ->
252 ("This record has more than one field named `" <> name <> "`.")
253 (text "There can only be one. Do some renaming to make sure the names are distinct!")
255 DuplicateValueDeclaration name ->
257 "DUPLICATE DEFINITION"
259 ( "Naming multiple top-level values " <> Help.functionName name <> " makes things\n"
260 <> "ambiguous. When you say " <> Help.functionName name <> " which one do you want?"
263 "Find all the top-level values named " <> Help.functionName name
264 <> " and do some renaming. Make sure the names are distinct!"
267 DuplicateTypeDeclaration name ->
269 "DUPLICATE DEFINITION"
271 ( "There are multiple types named `" <> name <> "` in this module."
274 "Search through this module, find all the types named `"
275 <> name <> "`, and give each of them a unique name."
278 DuplicateDefinition name ->
280 "DUPLICATE DEFINITION"
282 ("There are multiple values named `" <> name <> "` in this let-expression."
285 "Search through this let-expression, find all the values named `"
286 <> name <> "`, and give each of them a unique name."
289 UnboundTypeVarsInUnion typeName givenVars unbound ->
290 unboundTypeVars "type" typeName givenVars unbound
292 UnboundTypeVarsInAlias typeName givenVars unbound ->
293 unboundTypeVars "type alias" typeName givenVars unbound
295 UnusedTypeVarsInAlias typeName givenVars unused ->
297 "UNUSED TYPE VARIABLES"
299 ( "Type alias `" <> typeName <> "` cannot have unused type variables: "
300 <> Help.commaSep unused
303 [ text "You probably need to change the declaration like this:"
304 , dullyellow $ hsep $
305 map text ("type" : "alias" : typeName : filter (`notElem` unused) givenVars ++ ["=", "..."])
309 MessyTypeVarsInAlias typeName givenVars unused unbound ->
311 "TYPE VARIABLE PROBLEMS"
313 ( "Type alias `" <> typeName <> "` has some problems with type variables."
317 "The declaration says it uses certain type variables ("
318 <> Help.commaSep unused <> ") but they do not appear in the aliased type. "
319 <> "Furthermore, the aliased type says it uses type variables ("
320 <> Help.commaSep unbound
321 <> ") that do not appear in the declaration."
322 , text "You probably need to change the declaration like this:"
323 , dullyellow $ hsep $
324 map text ("type" : "alias" : typeName : filter (`notElem` unused) givenVars ++ unbound ++ ["=", "..."])
329unboundTypeVars :: Text -> Text -> [Text] -> [Text] -> Report.Report
330unboundTypeVars declKind typeName givenVars unboundVars =
332 "UNBOUND TYPE VARIABLES"
334 ( Help.capitalize declKind <> " `" <> typeName <> "` must declare its use of type variable"
335 <> Help.commaSep unboundVars
338 [ text "You probably need to change the declaration like this:"
340 map text (declKind : typeName : givenVars)
341 ++ map (dullyellow . text) unboundVars
342 ++ map text ["=", "..."]
344 "Here's why. Imagine one `" <> typeName <> "` where `" <> head unboundVars <>
345 "` is an Int and another where it is a Bool. When we explicitly list the type\
346 \ variables, the type checker can see that they are actually different types."
352-- PARSE ERROR TO REPORT
355parseReport :: Text -> Help.Doc -> Report.Report
356parseReport pre post =
357 Report.report "PARSE ERROR" Nothing pre post
360problemToReport :: Problem -> Report.Report
361problemToReport problem =
365 "I ran into a tab, but tabs are not allowed in Elm files."
366 (reflowParagraph "Replace the tab with spages.")
370 "I got to the end of the file while parsing a multi-line comment."
373 "Multi-line comments look like {- comment -}, and it looks like\
374 \ you are missing the closing marker."
376 "Nested multi-line comments like {- this {- and this -} -} are allowed.\
377 \ That means the opening and closing markers must be balanced, just\
378 \ like parentheses in normal code. Maybe that is the problem?"
384 "I got to the end of the file while parsing a GLSL block."
386 "A shader should be defined in a block like this: [glsl| ... |]"
391 "I got to the end of the file while parsing a string."
393 "Strings look like \"this\" with double quotes on each end.\
394 \ So the closing double quote seems to be missing."
397 EndOfFile_MultiString ->
399 "I got to the end of the file while parsing a multi-line string."
401 "Multi-line strings begin and end with three double quotes in a\
402 \ row, like \"\"\"this\"\"\". So the closing marker seems\
408 "This string is missing the closing quote."
411 "Elm strings must start and end with a double quote, like \"this\"."
413 "If you want a string that can contain newlines, use three double quotes in a\
414 \ row, like \"\"\"this\"\"\"."
420 "Ran into a bad escape code."
422 "Elm allows typical escape characters like \\n and \\t, but you can\
423 \ also use \\x0040 to refer to unicode characters by their hex code.\
424 \ It seems like something has gone wrong with one of these codes."
429 "Ran into a bad use of single quotes."
432 "If you want to create a string, just switch to double quotes:"
434 dullyellow (text "'this'")
436 <> dullyellow (text "\"this\"")
438 "Unlike JavaScript, Elm distinguishes between strings like \"hello\"\
439 \ and individual characters like 'A' and '3'. It is not all strings!\
440 \ If you really do want a character though, something went wrong\
441 \ and I did not find the closing single quote."
447 "Numbers cannot end with a decimal points."
449 "Leave it off or add some digits after it, like or 3 or 3.0"
454 "Numbers cannot have letters or underscores in them."
456 "Maybe a space is missing between a number and a variable?"
461 "If you put the letter E in a number, it should followed by more digits."
463 "If you want to say 1000, you can also say 1e3.\
464 \ You cannot just end it with an E though!"
469 "I see the start of a hex number, but not the end."
471 "A hex number looks like 0x123ABC, where the 0x is followed by hexidecimal digits (i.e. 0123456789abcdefABCDEF)"
476 "Normal numbers cannot start with a zero. Take the zeros off the front."
478 "Only numbers like 0x0040 or 0.25 can start with a zero."
483 "I ran into a problem while parsing this GLSL block."
484 (reflowParagraph msg)
486 BadChunkInQualifiedCapVar ->
491 "Single colons should only show up in types."
493 "Maybe you want :: instead? Or maybe you are defining\
494 \ a type annotation but there are extra spaces before it?"
499 "The = operator is reserved for defining variables."
501 "Maybe you want == instead? Or maybe you are defining a\
502 \ variable but there are extra spaces before it?"
507 "Arrows are reserved for cases and anonymous functions."
509 "Maybe you want > or >= instead?"
514 "Vertical bars are reserved for use in type declarations."
516 "Maybe you want || instead?"
521 "Dots are for record access and decimal points."
523 "They cannot float around on their own though, so\
524 \ maybe there is some extra whitespace?"
527 Theories allTheories ->
528 case Set.toList (Set.fromList allTheories) of
531 "Something went wrong when parsing this code."
533 "I do not have any suggestions though, and I suspect there is some\
534 \ sort of bug. Can you get it down to an <http://sscce.org> and\
535 \ share it at <https://github.com/elm-lang/error-message-catalog/issues>?\
536 \ That way we can figure out how to give better advice!"
540 error "TODO" (map theoryToText theories)
543theoryToText :: Theory -> Text
559 "a digit, like 0 or 6"
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list