1{-# OPTIONS_GHC -Wall #-}
2module Reporting.Error.Syntax where
4import qualified Data.List as List
5import qualified Text.Parsec.Error as Parsec
6import qualified Text.PrettyPrint as P
7import Text.PrettyPrint ((<+>))
9import qualified AST.Helpers as Help
10import qualified AST.Type as Type
11import Elm.Utils ((|>))
12import qualified Reporting.PrettyPrint as P
13import qualified Reporting.Report as Report
17 = Parse [Parsec.Message]
18 | InfixDuplicate String
19 | TypeWithoutDefinition String
20 | PortWithoutAnnotation String
21 | DuplicateValueDeclaration String
22 | DuplicateTypeDeclaration String
23 | DuplicateDefinition String
24 | UnboundTypeVarsInAlias String [String] String [String] Type.Raw
25 | UnboundTypeVarsInUnion String [String] String [String] [(String, [Type.Raw])]
30toReport :: Error -> Report.Report
36 "Problem when parsing your code!"
37 (unlines (map parseErrorHint messages))
39 InfixDuplicate opName ->
42 ("The infix declarations for " ++ operator ++ " must be removed.")
43 ("The precedence and associativity can only be set in one place, and\n"
44 ++ "this information has already been set somewhere else."
49 then "(" ++ opName ++ ")"
50 else "`" ++ opName ++ "`"
52 TypeWithoutDefinition valueName ->
55 ("There is a type annotation for '" ++ valueName ++ "' but there"
56 ++ "is no corresponding definition!"
58 ("Directly below the type annotation, put a definition like:\n\n"
59 ++ " " ++ valueName ++ " = 42"
62 PortWithoutAnnotation portName ->
65 ("Port '" ++ portName ++ "' does not have a type annotation!")
66 ("Directly above the port definition, I need something like this:\n\n"
67 ++ " port " ++ portName ++ " : Signal Int"
70 DuplicateValueDeclaration name ->
72 "DUPLICATE DEFINITION"
73 ("Naming multiple top-level values '" ++ name ++ "' makes things\n"
74 ++ "ambiguous. When you say '" ++ name ++ "' which one do you want?!"
76 ("Find all the top-level values named '" ++ name ++ "' and\n"
77 ++ "do some renaming. Make sure the names are distinct!"
80 DuplicateTypeDeclaration name ->
82 "DUPLICATE DEFINITION"
83 ("Naming multiple types '" ++ name ++ "' makes things ambiguous\n"
84 ++ "When you say '" ++ name ++ "' which one do you want?!"
86 ("Find all the types named '" ++ name ++ "' and\n"
87 ++ "do some renaming. Make sure the names are distinct!"
90 DuplicateDefinition name ->
92 "DUPLICATE DEFINITION"
93 ("Naming multiple values '" ++ name ++ "' in a single let-expression makes\n"
94 ++ "things ambiguous. When you say '" ++ name ++ "' which one do you want?!"
96 ("Find all the values named '" ++ name ++ "' in this let-expression and\n"
97 ++ "do some renaming. Make sure the names are distinct!"
100 UnboundTypeVarsInAlias typeName givenVars tvar tvars tipe ->
101 unboundTypeVars typeName tvar tvars $ P.render $
103 (P.text "type alias" <+> P.text typeName <+> P.hsep vars <+> P.equals)
105 (P.pretty False tipe)
107 vars = map P.text (givenVars ++ tvar : tvars)
110 UnboundTypeVarsInUnion typeName givenVars tvar tvars ctors ->
111 unboundTypeVars typeName tvar tvars $ P.render $
113 [ P.text "type" <+> P.text typeName <+> P.hsep vars
115 |> zipWith (<+>) (P.text "=" : repeat (P.text "|"))
120 vars = map P.text (givenVars ++ tvar : tvars)
122 P.text ctor <+> P.hsep (map (P.pretty True) args)
125unboundTypeVars :: String -> String -> [String] -> String -> Report.Report
126unboundTypeVars typeName tvar tvars revisedDeclaration =
129 ( "Not all type variables in '" ++ typeName ++ "' are listed, making sneaky\n"
130 ++ "type errors possible. Unbound type variables include: "
131 ++ List.intercalate ", " (tvar:tvars)
133 ( "You probably want this definition instead:\n"
134 ++ concatMap ("\n "++) (lines revisedDeclaration) ++ "\n\n"
135 ++ "Here's why. Imagine one '" ++ typeName ++ "' where '" ++ tvar ++ "' is an Int and\n"
136 ++ "another where it is a Bool. When we explicitly list the type variables, type\n"
137 ++ "checker can see that they are actually different types."
141parseErrorHint :: Parsec.Message -> String
142parseErrorHint message =
144 Parsec.SysUnExpect msg ->
145 "SysUnExpect: " ++ msg
147 Parsec.UnExpect msg ->
153 Parsec.Message msg ->
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