@@ -1,9 +1,48 @@
11module Reporting.Warning where
22
3+import qualified Text.PrettyPrint as P
4+import Text.PrettyPrint ((<+>))
5+
36import qualified AST.Module as Module
47import qualified AST.Type as Type
8+import qualified Reporting.Annotation as A
9+import qualified Reporting.PrettyPrint as P
10+import qualified Reporting.Report as Report
11+
512
13+-- ALL POSSIBLE WARNINGS
614
715data Warning
816 = UnusedImport Module.Name
917 | MissingTypeAnnotation String Type.Canonical
18+
19+
20+-- TO STRING
21+
22+toString :: String -> String -> A.Located Warning -> String
23+toString location source (A.A region warning) =
24+ Report.toString location region (toReport warning) source
25+
26+
27+toReport :: Warning -> Report.Report
28+toReport warning =
29+ case warning of
30+ UnusedImport moduleName ->
31+ Report.simple
32+ "warning"
33+ ("Module '" ++ Module.nameToString moduleName ++ "' is unused.")
34+ ""
35+
36+ MissingTypeAnnotation name inferredType ->
37+ Report.simple
38+ "warning"
39+ ("Top-level value '" ++ name ++ "' does not have a type annotation.")
40+ ( "The type annotation you want looks something like this:\n\n"
41+ ++ P.render (P.nest 4 typeDoc)
42+ )
43+ where
44+ typeDoc =
45+ P.hang
46+ (P.text name <+> P.colon)
47+ 4
48+ (P.pretty False inferredType)