@@ -230,7 +230,7 @@ toMismatchReport source localizer exprRegion category tipe expected =
233− FromAnnotation name arity subContext expectedType ->
233+ FromAnnotation name _arity subContext expectedType ->
234 Report.toCodeSnippet source exprRegion Nothing
234 Report.toCodeSnippet source exprRegion Nothing
236 H.reflow $
236 H.reflow $
@@ -259,39 +259,33 @@ toMismatchReport source localizer exprRegion category tipe expected =
260 "But the type annotation on `" <> N.toString name <> "` says it should be:"
260 "But the type annotation on `" <> N.toString name <> "` says it should be:"
262− [ error "TODO check for arity issues. Suggest that an arg is unlisted." arity
268 FromContext region context expectedType ->
266 FromContext region context expectedType ->
269 case context of
267 case context of
270 ListEntry index ->
268 ListEntry index ->
271− if Index.toHuman index == 2 then
272− error "TODO 1st vs 2nd list entry"
274− Report.toCodeSnippet source region (Just exprRegion)
269+ Report.toCodeSnippet source region (Just exprRegion)
276− H.reflow $
271+ H.reflow $
277− "The " <> H.ordinalize (Index.toHuman index) <> " element of this list does not match all the previous elements:"
272+ "The " <> H.ordinalize (Index.toHuman index) <> " element of this list does not match all the previous elements:"
279− typeComparison localizer tipe expectedType
274+ typeComparison localizer tipe expectedType
281− toDescription category $
276+ toDescription category $
282− "The " <> H.ordinalize (Index.toHuman index) <> " element is"
277+ "The " <> H.ordinalize (Index.toHuman index) <> " element is"
284− "But all the previous elements in the list are:"
279+ "But all the previous elements in the list are:"
286− [ H.toSimpleHint $
281+ [ H.toSimpleHint $
287− "Everything in the list needs to be the same type of value.\
282+ "Everything in the list needs to be the same type of value.\
288− \ This way you never run into unexpected values partway through.\
283+ \ This way you never run into unexpected values partway through.\
289− \ To mix different types in a single list, create a \"union type\" as\
284+ \ To mix different types in a single list, create a \"union type\" as\
290− \ described in: <http://guide.elm-lang.org/types/union_types.html>"
285+ \ described in: <http://guide.elm-lang.org/types/union_types.html>"
296 Negate ->
290 Negate ->
297 Report.toCodeSnippet source region (Just exprRegion)
291 Report.toCodeSnippet source region (Just exprRegion)
@@ -337,57 +331,48 @@ toMismatchReport source localizer exprRegion category tipe expected =
339 IfBranch index ->
333 IfBranch index ->
340− if Index.toHuman index == 2 then
341− error "TODO 1st vs 2nd if branches"
342− -- error "TODO if with no chaining"
344− Report.toCodeSnippet source region (Just exprRegion)
334+ Report.toCodeSnippet source region (Just exprRegion)
346− H.reflow $
336+ H.reflow $
347− "The " <> H.ordinalize (Index.toHuman index) <> " branch of this `if` does not match all the previous branches:"
337+ "The " <> H.ordinalize (Index.toHuman index) <> " branch of this `if` does not match all the previous branches:"
349− typeComparison localizer tipe expectedType
339+ typeComparison localizer tipe expectedType
351− toDescription category $
341+ toDescription category $
352− "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
342+ "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
354− "But all the previous branches result in:"
344+ "But all the previous branches result in:"
356− [ H.link "Hint"
346+ [ H.link "Hint"
357− "All branches in an `if` must produce the same type of values. This way, no\
347+ "All branches in an `if` must produce the same type of values. This way, no\
358− \ matter which branch we take, the result is always a consistent shape. Read"
348+ \ matter which branch we take, the result is always a consistent shape. Read"
359− "union-types"
349+ "union-types"
360− "to learn how to “mix” types."
350+ "to learn how to “mix” types."
366 CaseBranch index ->
355 CaseBranch index ->
367− if Index.toHuman index == 2 then
368− error "TODO 1st vs 2nd case branches"
370− Report.toCodeSnippet source region (Just exprRegion)
356+ Report.toCodeSnippet source region (Just exprRegion)
372− H.reflow $
358+ H.reflow $
373− "The " <> H.ordinalize (Index.toHuman index) <> " branch of this `case` does not match all the previous branches:"
359+ "The " <> H.ordinalize (Index.toHuman index) <> " branch of this `case` does not match all the previous branches:"
375− typeComparison localizer tipe expectedType
361+ typeComparison localizer tipe expectedType
377− toDescription category $
363+ toDescription category $
378− "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
364+ "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
380− "But all the previous branches result in:"
366+ "But all the previous branches result in:"
382− [ H.link "Hint"
368+ [ H.link "Hint"
383− "All branches in a `case` must produce the same type of values. This way, no\
369+ "All branches in a `case` must produce the same type of values. This way, no\
384− \ matter which branch we take, the result is always a consistent shape. Read"
370+ \ matter which branch we take, the result is always a consistent shape. Read"
385− "union-types"
371+ "union-types"
386− "to learn how to “mix” types."
372+ "to learn how to “mix” types."
392 CallArg maybeFuncName index ->
377 CallArg maybeFuncName index ->
@@ -508,7 +493,7 @@ toMismatchReport source localizer exprRegion category tipe expected =
509 RecordAccess field ->
494 RecordAccess field ->
510 Report.toCodeSnippet source region (Just exprRegion) $
495 Report.toCodeSnippet source region (Just exprRegion) $
511− case error "TODO figure out record things" tipe of
496+ case tipe of
512 T.Record _ _ ->
497 T.Record _ _ ->
514 H.reflow $
499 H.reflow $
@@ -521,62 +506,38 @@ toMismatchReport source localizer exprRegion category tipe expected =
521 , H.reflow $
506 , H.reflow $
522 "So maybe the ." <> N.toString field <> " field access is misspelled?"
507 "So maybe the ." <> N.toString field <> " field access is misspelled?"
525− case error "TODO closeNames" of
531− ["It","may","also","be","a","typo","in","the","record","itself."
532− ,"Perhaps","the",H.dullyellow name,"field","is","misspelled?"
538− ["It","may","also","be","a","typo","in","the","record","itself."
541− ++ H.commaSep "or" H.dullyellow names
542− ++ ["field","is","misspelled?"]
549− "I cannot access field `" <> N.toString field <> "` of this " <> whatever <> ":"
553− "The " <> whatever <> " is not a record! It is actually a function:"
554− , indentType localizer tipe
555− , H.toSimpleHint "Maybe it is missing some arguments?"
561 H.reflow $
513 H.reflow $
562− "I cannot access field `" <> N.toString field <> "` of this " <> whatever <> ":"
514+ "This is not a record, so it has no fields to access!"
565− [ H.reflow $
517+ [ H.reflow $ toDescription category "It is"
566− "The " <> whatever <> " is not a record though! It is a:"
567 , indentType localizer tipe
518 , indentType localizer tipe
520+ ["But","I","need","a","record","with","a",H.dullyellow (H.nameToDoc field),"field!"]
571 RecordUpdate ->
524 RecordUpdate ->
572− case error "TODO figure out record things" tipe of
525+ case tipe of
573 T.Record _ _ ->
526 T.Record _ _ ->
574− Report.toCodeSnippet source region Nothing
527+ Report.toCodeSnippet source region Nothing $
576 H.reflow $
529 H.reflow $
577 "I think there is a typo in one of these field names:"
530 "I think there is a typo in one of these field names:"
579− error "TODO record update field name typo"
532+ typeComparison localizer tipe expectedType
534+ "The record you want to update has type:"
536+ "But you are saying it should have these fields:"
538+ [ H.reflow "Maybe there is some typo?"
@@ -585,14 +546,27 @@ toMismatchReport source localizer exprRegion category tipe expected =
585 "The record update syntax does not work with this value:"
546 "The record update syntax does not work with this value:"
588− [ H.reflow $
549+ [ H.reflow $ toDescription category "It is"
589− "I can only update records, but this appears to be a " <> whatever <> ":"
590 , indentType localizer tipe
550 , indentType localizer tipe
551+ , H.reflow $ "But I need some kind of record here!"
594 Destructure ->
555 Destructure ->
595− error "TODO Destructure"
556+ Report.toCodeSnippet source region Nothing
559+ "I cannot destructure "
561+ typeComparison localizer tipe expectedType
563+ toDescription category "You are defining"
565+ "But then trying to destructure it as:"
@@ -618,15 +592,15 @@ opLeftToDocs localizer category op tipe expectedType =
618 case op of
592 case op of
620 | isString tipe -> badStringAdd
594 | isString tipe -> badStringAdd
621− | isList tipe -> badListAdd localizer "left" tipe
595+ | isList tipe -> badListAdd localizer category "left" tipe
622− | otherwise -> badMath localizer "Addition" "left" "+" tipe []
596+ | otherwise -> badMath localizer category "Addition" "left" "+" tipe []
625− | isList tipe -> badListMul localizer "left" tipe
599+ | isList tipe -> badListMul localizer category "left" tipe
626− | otherwise -> badMath localizer "Multiplication" "left" "*" tipe []
600+ | otherwise -> badMath localizer category "Multiplication" "left" "*" tipe []
628− "-" -> badMath localizer "Subtraction" "left" "-" tipe []
602+ "-" -> badMath localizer category "Subtraction" "left" "-" tipe []
629− "^" -> badMath localizer "Exponentiation" "left" "^" tipe []
603+ "^" -> badMath localizer category "Exponentiation" "left" "^" tipe []
630 "/" -> badFDiv localizer "left" tipe
604 "/" -> badFDiv localizer "left" tipe
631 "//" -> badIDiv localizer "left" tipe
605 "//" -> badIDiv localizer "left" tipe
632 "&&" -> badBool localizer "&&" "left" tipe
606 "&&" -> badBool localizer "&&" "left" tipe
@@ -640,18 +614,9 @@ opLeftToDocs localizer category op tipe expectedType =
640 ( "The left side of (<|) needs to be a function so I can pipe arguments to it!"
614 ( "The left side of (<|) needs to be a function so I can pipe arguments to it!"
643− [ H.reflow $
617+ [ H.reflow $ toDescription category "I am seeing"
644− "Instead of a function, I am seeing " <> whatever <> ":"
645 , indentType localizer tipe
618 , indentType localizer tipe
646− , error "TODO"
619+ , H.reflow $ "This needs to be some kind of function though!"
650− "Maybe you gave " <> funcName <> " too many arguments already?"
@@ -687,24 +652,24 @@ opRightToDocs localizer category op tipe expectedType =
687 | isInt tipe -> badCast op FloatInt
652 | isInt tipe -> badCast op FloatInt
688 | isFloat tipe -> badCast op IntFloat
653 | isFloat tipe -> badCast op IntFloat
689 | isString tipe -> EmphRight $ badStringAdd
654 | isString tipe -> EmphRight $ badStringAdd
690− | isList tipe -> EmphRight $ badListAdd localizer "right" tipe
655+ | isList tipe -> EmphRight $ badListAdd localizer category "right" tipe
691− | otherwise -> EmphRight $ badMath localizer "Addition" "right" "+" tipe []
656+ | otherwise -> EmphRight $ badMath localizer category "Addition" "right" "+" tipe []
694 | isInt tipe -> badCast op FloatInt
659 | isInt tipe -> badCast op FloatInt
695 | isFloat tipe -> badCast op IntFloat
660 | isFloat tipe -> badCast op IntFloat
696− | isList tipe -> EmphRight $ badListMul localizer "right" tipe
661+ | isList tipe -> EmphRight $ badListMul localizer category "right" tipe
697− | otherwise -> EmphRight $ badMath localizer "Multiplication" "right" "*" tipe []
662+ | otherwise -> EmphRight $ badMath localizer category "Multiplication" "right" "*" tipe []
700 | isInt tipe -> badCast op FloatInt
665 | isInt tipe -> badCast op FloatInt
701 | isFloat tipe -> badCast op IntFloat
666 | isFloat tipe -> badCast op IntFloat
702− | otherwise -> EmphRight $ badMath localizer "Subtraction" "right" "-" tipe []
667+ | otherwise -> EmphRight $ badMath localizer category "Subtraction" "right" "-" tipe []
705 | isInt tipe -> badCast op FloatInt
670 | isInt tipe -> badCast op FloatInt
706 | isFloat tipe -> badCast op IntFloat
671 | isFloat tipe -> badCast op IntFloat
707− | otherwise -> EmphRight $ badMath localizer "Exponentiation" "right" "^" tipe []
672+ | otherwise -> EmphRight $ badMath localizer category "Exponentiation" "right" "^" tipe []
709 "/" -> EmphRight $ badFDiv localizer "right" tipe
674 "/" -> EmphRight $ badFDiv localizer "right" tipe
710 "//" -> EmphRight $ badIDiv localizer "right" tipe
675 "//" -> EmphRight $ badIDiv localizer "right" tipe
@@ -724,7 +689,7 @@ opRightToDocs localizer category op tipe expectedType =
724 EmphRight
689 EmphRight
726 H.reflow $
691 H.reflow $
727− "I cannot pipe this " <> whatever <> " in as the final argument:"
692+ "I cannot send this through the (<|) pipe:"
729 typeComparison localizer tipe expectedType
694 typeComparison localizer tipe expectedType
@@ -732,9 +697,7 @@ opRightToDocs localizer category op tipe expectedType =
733 "But (<|) is piping it a function that expects:"
698 "But (<|) is piping it a function that expects:"
735− [ "Maybe an argument is missing?"
@@ -743,29 +706,15 @@ opRightToDocs localizer category op tipe expectedType =
743 (T.Lambda expectedArgType _ _, T.Lambda argType _ _) ->
706 (T.Lambda expectedArgType _ _, T.Lambda argType _ _) ->
744 EmphRight
707 EmphRight
746− -- TODO try to say the function name instead of "this function"
747− "I cannot pipe the argument through to this function:"
709+ "This function cannot handle the argument sent through the (|>) pipe:"
749 typeComparison localizer argType expectedArgType
711 typeComparison localizer argType expectedArgType
751 "You are providing an argument of type:"
713 "You are providing an argument of type:"
753 "But (|>) is piping it a function that expects its next argument to be:"
715 "But (|>) is piping it a function that expects its next argument to be:"
757− "But (|>) is piping it a function that expects the next argument to be:"
759− Just (FuncName name) ->
760− "But (|>) is piping it to `" <> N.toString name <> "` which expects the next argument to be:"
763− "But (|>) is piping it to (" <> N.toString op <> ") which expects the next argument to be:"
766− [ "Maybe an argument is missing?"
@@ -775,18 +724,9 @@ opRightToDocs localizer category op tipe expectedType =
775 "The right side of (|>) needs to be a function so I can pipe arguments to it!"
724 "The right side of (|>) needs to be a function so I can pipe arguments to it!"
778− [ H.reflow $
727+ [ H.reflow $ toDescription category $
779− "Instead of a function, I am seeing " <> whatever <> ":"
728+ "Instead of a function, I am seeing "
780 , indentType localizer tipe
729 , indentType localizer tipe
785− "Maybe you gave " <> funcName <> " too many arguments already?"
@@ -802,12 +742,11 @@ opRightToDocs localizer category op tipe expectedType =
803 "But (" <> N.toString op <> ") needs the right argument to be:"
743 "But (" <> N.toString op <> ") needs the right argument to be:"
805− error "TODO"
745+ [ H.toSimpleHint $
806− {-
746+ "With operators like (" ++ N.toString op ++ ") I always check the left\
807− [ problem
747+ \ side first. If it seems fine, I assume it is correct and check the right\
808− , binopHint home op leftType rightType
748+ \ side. So the problem may be in how the left and right arguments interact!"
@@ -853,11 +792,6 @@ isList tipe =
858− error "TODO whatever"
862-- BAD MATH
796-- BAD MATH
@@ -920,14 +854,14 @@ badStringAdd =
923−badListAdd :: T.Localizer -> String -> T.Type -> (H.Doc, H.Doc)
857+badListAdd :: T.Localizer -> Category -> String -> T.Type -> (H.Doc, H.Doc)
924−badListAdd localizer direction tipe =
858+badListAdd localizer category direction tipe =
926 "I cannot do addition with lists:"
860 "I cannot do addition with lists:"
929− [ H.reflow $
863+ [ H.reflow $ toDescription category $
930− "The " <> direction <> " side of (+) is " <> whatever <> ":"
864+ "The " <> direction <> " side of (+) is"
931 , indentType localizer tipe
865 , indentType localizer tipe
932 , H.fillSep
866 , H.fillSep
933 ["But","(+)","only","works","with",H.dullyellow "Int","and",H.dullyellow "Float","values."
867 ["But","(+)","only","works","with",H.dullyellow "Int","and",H.dullyellow "Float","values."
@@ -939,9 +873,9 @@ badListAdd localizer direction tipe =
942−badListMul :: T.Localizer -> String -> T.Type -> (H.Doc, H.Doc)
876+badListMul :: T.Localizer -> Category -> String -> T.Type -> (H.Doc, H.Doc)
943−badListMul localizer direction tipe =
877+badListMul localizer category direction tipe =
944− badMath localizer "Multiplication" direction "*" tipe
878+ badMath localizer category "Multiplication" direction "*" tipe
946 H.toFancyHint
880 H.toFancyHint
947 [ "Maybe", "you", "want"
881 [ "Maybe", "you", "want"
@@ -951,21 +885,20 @@ badListMul localizer direction tipe =
954−badMath :: T.Localizer -> String -> String -> String -> T.Type -> [H.Doc] -> (H.Doc, H.Doc)
888+badMath :: T.Localizer -> Category -> String -> String -> String -> T.Type -> [H.Doc] -> (H.Doc, H.Doc)
955−badMath localizer operation direction op tipe otherHints =
889+badMath localizer category operation direction op tipe otherHints =
957 H.reflow $
891 H.reflow $
958 operation ++ " does not work with this value:"
892 operation ++ " does not work with this value:"
960 H.stack $
894 H.stack $
961− [ H.reflow $
895+ [ H.reflow $ toDescription category $
962− "The " <> direction <> " side of (" <> op <> ") is a " <> whatever <> ":"
896+ "The " <> direction <> " side of (" <> op <> ") is"
963 , indentType localizer tipe
897 , indentType localizer tipe
964 , H.fillSep
898 , H.fillSep
965 ["But","(" <> H.text op <> ")","only","works","with"
899 ["But","(" <> H.text op <> ")","only","works","with"
966 ,H.dullyellow "Int","and",H.dullyellow "Float","values."
900 ,H.dullyellow "Int","and",H.dullyellow "Float","values."
968− , error "TODO check for missing arguments"
970 ++ otherHints
903 ++ otherHints
@@ -1136,8 +1069,6 @@ badEquality localizer op tipe expectedType =
1136 [ H.reflow $
1069 [ H.reflow $
1137 "Different types can never be equal though! Which side is messed up?"
1070 "Different types can never be equal though! Which side is messed up?"
1140−-- error "TODO detect problems here instead?"