@@ -168,14 +168,195 @@ toReport source localizer err =
168 toExprReport source localizer region category actualType expected
168 toExprReport source localizer region category actualType expected
170 BadPattern region category tipe expected ->
170 BadPattern region category tipe expected ->
171− error "TODO" region category tipe expected
171+ toPatternReport source localizer region category tipe expected
173 InfiniteType overallType ->
173 InfiniteType overallType ->
174 error "TODO" source localizer overallType
174 error "TODO" source localizer overallType
181+toPatternReport :: Code.Source -> T.Localizer -> R.Region -> PCategory -> T.Type -> PExpected T.Type -> Report.Report
182+toPatternReport source localizer patternRegion category tipe expected =
183+ Report.Report "TYPE MISMATCH" patternRegion [] $
185+ PNoExpectation expectedType ->
186+ Report.toCodeSnippet source patternRegion Nothing $
188+ "This pattern is being used in an unexpected way:"
190+ patternTypeComparison localizer tipe expectedType
192+ toPatternDescription category "It is"
194+ "But it needs to match values of type:"
200+ PFromContext region context expectedType ->
201+ Report.toCodeSnippet source region (Just patternRegion) $
203+ PTypedArg name index ->
206+ "The " <> H.ordinalize (Index.toHuman index) <> " argument to `" <> N.toString name <> "` is weird."
208+ patternTypeComparison localizer tipe expectedType
210+ toPatternDescription category $
211+ "The argument is a pattern that matches"
213+ "But the type annotation on `" <> N.toString name <> "` says the " <> H.ordinalize (Index.toHuman index) <> " argument should be:"
220+ if index == Index.first then
223+ "The 1st pattern in this `case` causing a mismatch:"
225+ patternTypeComparison localizer tipe expectedType
227+ toPatternDescription category "The first pattern is trying to match"
229+ "But it is supposed to match an expression of type:"
232+ "Is the pattern the problem? Or is it the expression you are trying to match on?"
239+ "The " <> H.ordinalize (Index.toHuman index) <> " pattern in this `case` does not match the previous ones."
241+ patternTypeComparison localizer tipe expectedType
243+ toPatternDescription category $
244+ "The " <> H.ordinalize (Index.toHuman index) <> " pattern is trying to match"
246+ "But all the previous patterns match values of type:"
252+ PCtorArg name index ->
255+ "The " <> H.ordinalize (Index.toHuman index) <> " argument to `" <> N.toString name <> "` is weird."
257+ patternTypeComparison localizer tipe expectedType
259+ toPatternDescription category "It is trying to match"
261+ "But `" <> N.toString name <> "` needs its " <> H.ordinalize (Index.toHuman index) <> " argument to be:"
270+ "The " <> H.ordinalize (Index.toHuman index) <> " pattern in this list does not match all the previous ones:"
272+ patternTypeComparison localizer tipe expectedType
274+ toPatternDescription category $
275+ "The " <> H.ordinalize (Index.toHuman index) <> " pattern is trying to match"
277+ "But all the previous patterns in the list are:"
280+ "Everything in the list needs to be the same type of value.\
281+ \ This way you never run into unexpected values partway through.\
282+ \ To mix different types in a single list, create a \"union type\" as\
283+ \ described in: <http://guide.elm-lang.org/types/union_types.html>"
291+ "The pattern after (::) is causing issues."
293+ patternTypeComparison localizer tipe expectedType
295+ toPatternDescription category $
296+ "The pattern after (::) is trying to match"
298+ "But it needs to match lists like this:"
178−-- HELPERS
306+-- PATTERN HELPERS
309+patternTypeComparison :: T.Localizer -> T.Type -> T.Type -> ( String, String, [H.Doc] ) -> H.Doc
310+patternTypeComparison localizer actual expected ( iAmSeeing, insteadOf, soHereAreSomeThoughts ) =
312+ (actualDoc, expectedDoc) =
313+ error "TODO diff" localizer actual expected
316+ [ H.reflow iAmSeeing
317+ , H.indent 4 actualDoc
318+ , H.reflow insteadOf
319+ , H.indent 4 expectedDoc
321+ ++ soHereAreSomeThoughts
324+toPatternDescription :: PCategory -> String -> String
325+toPatternDescription category iAmTryingToMatch =
328+ PRecord -> " record values of type:"
329+ PUnit -> " unit values:"
330+ PTuple -> " tuples of type:"
331+ PList -> " lists of type:"
332+ PCtor name -> " `" <> N.toString name <> "` values of type:"
333+ PInt -> " integers:"
335+ PChr -> " characters:"
342+typeComparison :: T.Localizer -> T.Type -> T.Type -> ( String, String, [H.Doc] ) -> H.Doc
343+typeComparison localizer actual expected ( iAmSeeing, insteadOf, soHereAreSomeThoughts ) =
345+ (actualDoc, expectedDoc) =
346+ error "TODO diff" localizer actual expected
349+ [ H.reflow iAmSeeing
350+ , H.indent 4 actualDoc
351+ , H.reflow insteadOf
352+ , H.indent 4 expectedDoc
354+ ++ soHereAreSomeThoughts
357+indentType :: T.Localizer -> T.Type -> H.Doc
358+indentType localizer tipe =
359+ H.indent 4 (H.dullyellow (T.toDoc localizer RT.None tipe))
181toDescription :: Category -> String -> String
362toDescription :: Category -> String -> String
@@ -1069,28 +1250,3 @@ badEquality localizer op tipe expectedType =
1078−typeComparison :: T.Localizer -> T.Type -> T.Type -> ( String, String, [H.Doc] ) -> H.Doc
1079−typeComparison localizer actual expected ( iAmSeeing, insteadOf, soHereAreSomeThoughts ) =
1081− (actualDoc, expectedDoc) =
1082− error "TODO diff" localizer actual expected
1085− [ H.reflow iAmSeeing
1086− , H.indent 4 actualDoc
1087− , H.reflow insteadOf
1088− , H.indent 4 expectedDoc
1090− ++ soHereAreSomeThoughts
1093−indentType :: T.Localizer -> T.Type -> H.Doc
1094−indentType localizer tipe =
1095− H.indent 4 (H.dullyellow (T.toDoc localizer RT.None tipe))