on master help sign in
Resolve TODOs in Validate
commit70933c9f85e0403bd5a3ceff4a1ccb5b7806bc98 authorEvan Czaplicki <evancz@users.noreply.github.com> dateWed 31 Jan 2018, 19:02 (9 years ago) parenta5a5196
2 files changed+43−24
src/Reporting/Error/Syntax.hs+24−5 src/Validate.hs+19−19
src/Reporting/Error/Syntax.hs+24−5
@@ -30,6 +30,7 @@ import qualified Reporting.Helpers as H
3030data Error
3131 = CommentOnNothing R.Region
3232 | UnexpectedPort R.Region N.Name
33+ | TypeWithBadDefinition R.Region N.Name N.Name
3334 | TypeWithoutDefinition R.Region N.Name
3435 | Parse R.Region (Maybe R.Region) Problem
3536
@@ -89,7 +90,7 @@ data Theory
8990data Next
9091 = Decl
9192 | Expr
92− | AfterOpExpr Text
93+ | AfterOpExpr N.Name
9394 | ElseBranch
9495 | Arg
9596 | Pattern
@@ -127,7 +128,7 @@ data Context
127128 | TypeAlias
128129 | Infix
129130 | Port
130− deriving (Eq, Ord, Show)
131+ deriving (Eq, Ord)
131132
132133
133134
@@ -165,16 +166,34 @@ toReport source err =
165166 ]
166167 )
167168
168− TypeWithoutDefinition region valueName ->
169+ TypeWithBadDefinition region annName defName ->
170+ Report.Report "ANNOTATION MISMATCH" region [] $
171+ Report.toCodeSnippet source region Nothing
172+ (
173+ H.reflow $
174+ "I see a `" <> N.toString annName
175+ <> "` annotation, but it is followed by a `"
176+ <> N.toString defName <> "` definition."
177+ ,
178+ H.fillSep
179+ ["The","annotation","and","definition","names","must","match!"
180+ ,"Is","there","a","typo","between"
181+ , H.dullyellow (H.nameToDoc annName)
182+ ,"and"
183+ , H.dullyellow (H.nameToDoc defName) <> "?"
184+ ]
185+ )
186+
187+ TypeWithoutDefinition region name ->
169188 Report.Report "MISSING DEFINITION" region [] $
170189 Report.toCodeSnippet source region Nothing
171190 (
172191 H.reflow $
173− "There is a type annotation for `" <> N.toString valueName
192+ "There is a type annotation for `" <> N.toString name
174193 <> "` but there is no corresponding definition!"
175194 ,
176195 "Directly below the type annotation, put a definition like:\n\n"
177− <> " " <> H.nameToDoc valueName <> " = 42"
196+ <> " " <> H.nameToDoc name <> " = 42"
178197 )
179198
180199 Parse region subRegion problem ->
src/Validate.hs+19−19
@@ -85,7 +85,7 @@ vsdHelp decls stuff =
8585 vsdHelp otherDecls $ stuff { _ports = port_ : _ports stuff }
8686
8787 Src.Docs docs ->
88− validateDocs docs otherDecls stuff
88+ validateDocs region docs otherDecls stuff
8989
9090 Src.Annotation (A.At _ name) tipe ->
9191 validateAnnotation region name tipe otherDecls stuff
@@ -100,40 +100,40 @@ vsdHelp decls stuff =
100100-- VALIDATE DOCS
101101
102102
103−validateDocs :: Text -> [Src.Decl] -> Stuff -> Result i w Stuff
104−validateDocs docs decls stuff =
103+validateDocs :: R.Region -> Text -> [Src.Decl] -> Stuff -> Result i w Stuff
104+validateDocs region docs decls stuff =
105105 case decls of
106106 [] ->
107− error "TODO no docs on nothing"
107+ Result.throw (Error.CommentOnNothing region)
108108
109109 A.At _ decl : _ ->
110− do name <- getNameForDocs decl
110+ do name <- getNameForDocs region decl
111111 vsdHelp decls $ stuff { _docs = Map.insert name docs (_docs stuff) }
112112
113113
114−getNameForDocs :: Src.Decl_ -> Result i w N.Name
115−getNameForDocs decl =
114+getNameForDocs :: R.Region -> Src.Decl_ -> Result i w N.Name
115+getNameForDocs region decl =
116116 case decl of
117117 Src.Union (A.At _ name) _ _ ->
118− return name
118+ Result.ok name
119119
120120 Src.Alias (A.At _ name) _ _ ->
121− return name
121+ Result.ok name
122122
123− Src.Binop _ _ _ _ ->
124− error "TODO no docs on binop"
123+ Src.Binop name _ _ _ ->
124+ Result.ok name
125125
126− Src.Port _ _ ->
127− error "TODO no docs on ports"
126+ Src.Port (A.At _ name) _ ->
127+ Result.ok name
128128
129129 Src.Docs _ ->
130− error "TODO no docs on docs"
130+ Result.throw (Error.CommentOnNothing region)
131131
132132 Src.Annotation (A.At _ name) _ ->
133− return name
133+ Result.ok name
134134
135135 Src.Definition (A.At _ name) _ _ ->
136− return name
136+ Result.ok name
137137
138138
139139
@@ -144,7 +144,7 @@ validateAnnotation :: R.Region -> N.Name -> Src.Type -> [Src.Decl] -> Stuff -> R
144144validateAnnotation annRegion annotationName tipe decls stuff =
145145 case decls of
146146 [] ->
147− error "TODO no attotations on nothing"
147+ Result.throw (Error.TypeWithoutDefinition annRegion annotationName)
148148
149149 A.At defRegion decl : otherDecls ->
150150 case decl of
@@ -156,10 +156,10 @@ validateAnnotation annRegion annotationName tipe decls stuff =
156156 vsdHelp otherDecls $ stuff { _decls = validDecl : _decls stuff }
157157
158158 else
159− error "TODO annotation does not match following definition"
159+ Result.throw (Error.TypeWithBadDefinition annRegion annotationName definitionName)
160160
161161 _ ->
162− error "TODO annotation needs to be on a definition"
162+ Result.throw (Error.TypeWithoutDefinition annRegion annotationName)
163163
164164
165165