@@ -39,10 +39,14 @@ data Mismatch = MismatchInfo
3939
4040data Reason
4141 = MessyFields [String] [String]
42− | NotRecord
42+ | NotNumber
43+ | NotComparable
44+ | NotAppendable
45+ | NotCompAppend
46+ | IntFloat
4347 | TooLongComparableTuple Int
4448 | Rigid (Maybe String)
45− deriving (Show)
49+ | DoubleRigid
4650
4751
4852data Hint
@@ -117,7 +121,7 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
117121 cmpHint leftWords rightWords extraHints =
118122 comparisonHint localizer leftType rightType leftWords rightWords
119123 ( map toHint extraHints
120− ++ Maybe.maybeToList (fmap reasonToString maybeReason)
124+ ++ Maybe.maybeToList (reasonToString =<< maybeReason)
121125 )
122126 in
123127 case hint of
@@ -141,7 +145,10 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
141145 ( "All the branches of this case-expression are consistent, but the overall\n"
142146 ++ "type does not match how it is used elsewhere."
143147 )
144− ( error "TODO generic error"
148+ ( cmpHint
149+ "The `case` evaluates to something of type:"
150+ "Which is fine, but the surrounding context wants it to be:"
151+ []
145152 )
146153
147154 IfCondition ->
@@ -340,7 +347,10 @@ mismatchToReport localizer (MismatchInfo hint leftType rightType maybeReason) =
340347 report
341348 Nothing
342349 "There is some problem with this GLSL shader."
343− ( error "TODO generic error"
350+ ( cmpHint
351+ "The shader block has this type:"
352+ "Which is fine, but the surrounding context wants it to be:"
353+ []
344354 )
345355
346356 Range ->
@@ -425,31 +435,67 @@ funcName maybeVar =
425435-- MISMTACH REASONS
426436
427437
428−reasonToString :: Reason -> Doc
438+reasonToString :: Reason -> Maybe Doc
429439reasonToString reason =
440+ let
441+ go msg =
442+ Just (toHint msg)
443+ in
430444 case reason of
431445 MessyFields leftOnly rightOnly ->
432− let
433− maybeMessage =
434− do let typos = RenderType.findPotentialTypos leftOnly rightOnly
435− RenderType.vetTypos typos
436− misspellingMessage typos
437− in
438− case maybeMessage of
439− Just doc ->
440− doc
446+ do let typos = RenderType.findPotentialTypos leftOnly rightOnly
447+ _ <- RenderType.vetTypos typos
448+ misspellingMessage typos
449+
450+ NotNumber ->
451+ go "Valid number types include Int and Float."
452+
453+ NotComparable ->
454+ go "Valid comparable types include Int, Float, Char, String, lists, and tuples."
441455
442− Nothing ->
443− error "TODO"
456+ NotAppendable ->
457+ go "Valid appendable types include String, Text, and List."
444458
445− NotRecord ->
446− toHint "A record cannot be merged with other types of values."
459+ NotCompAppend ->
460+ go "Valid `number` types include Int and Float."
461+
462+ IntFloat ->
463+ go
464+ "Elm does not automatically convert between Ints and Floats. Use\
465+ \ `toFloat` and `round` to do specific conversions.\
466+ \ <http://package.elm-lang.org/packages/elm-lang/core/latest/Basics#toFloat>"
447467
448468 TooLongComparableTuple len ->
449− error "TODO"
469+ go $
470+ "Although tuples are comparable, this is currently only supported\
471+ \ for tuples with 6 or fewer entries, not " ++ show len ++ "."
472+
473+ Rigid (Just name) ->
474+ go $
475+ "It is very likely that a type annotation is too generic. Type variable\
476+ \ `" ++ name ++ "` is saying *many* kinds of value can be given, but the\
477+ \ actual definition needs a more specific type. I am not sure whether the\
478+ \ type annotation or the definition is \"right\" though, you may have to\
479+ \ make the annotation more specific or make the definition more generic."
480+
481+ Rigid Nothing ->
482+ go $
483+ "It is very likely that a type annotation is too generic. One type is saying\
484+ \ *many* kinds of value can be given, but the other needs a more specific type."
485+
486+ DoubleRigid ->
487+ Just $ Help.stack $
488+ [ hintDoc <> text "This usually happens when a few factors come together."
489+ , indent 4 $ vcat $
490+ [ text "1. You have a generic function with a type annotation."
491+ , text "2. In its definition, there is a `let` with generic type annotations."
492+ ]
493+ , Help.reflowParagraph
494+ "The issue is that these type variables are not actually shared between\
495+ \ outer and inner type annotations right now. You can usually fix this by\
496+ \ commenting out the inner type annotations."
497+ ]
450498
451− Rigid maybeName ->
452− error "TODO"
453499
454500
455501hintDoc :: Doc