on master help sign in
Get rid of a bunch of TODOs in type errors
3d14963Evan Czaplicki
src/Reporting/Error/Type.hs+129−198
@@ -230,7 +230,7 @@ toMismatchReport source localizer exprRegion category tipe expected =
230 )
230 )
231 )
231 )
232
232
233− FromAnnotation name arity subContext expectedType ->
233+ FromAnnotation name _arity subContext expectedType ->
234 Report.toCodeSnippet source exprRegion Nothing
234 Report.toCodeSnippet source exprRegion Nothing
235 (
235 (
236 H.reflow $
236 H.reflow $
@@ -259,39 +259,33 @@ toMismatchReport source localizer exprRegion category tipe expected =
259 ,
259 ,
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:"
261 ,
261 ,
262− [ error "TODO check for arity issues. Suggest that an arg is unlisted." arity
263− --, problem
264− ]
262+ []
265 )
263 )
266 )
264 )
267
265
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"
273− else
274− Report.toCodeSnippet source region (Just exprRegion)
269+ Report.toCodeSnippet source region (Just exprRegion)
275− (
270+ (
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:"
278− ,
273+ ,
279− typeComparison localizer tipe expectedType
274+ typeComparison localizer tipe expectedType
280− (
275+ (
281− toDescription category $
276+ toDescription category $
282− "The " <> H.ordinalize (Index.toHuman index) <> " element is"
277+ "The " <> H.ordinalize (Index.toHuman index) <> " element is"
283− ,
278+ ,
284− "But all the previous elements in the list are:"
279+ "But all the previous elements in the list are:"
285− ,
280+ ,
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>"
291− --, problem
292− ]
286+ ]
293− )
287+ )
294− )
288+ )
295
289
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 =
337 )
331 )
338
332
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"
343− else
344− Report.toCodeSnippet source region (Just exprRegion)
334+ Report.toCodeSnippet source region (Just exprRegion)
345− (
335+ (
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:"
348− ,
338+ ,
349− typeComparison localizer tipe expectedType
339+ typeComparison localizer tipe expectedType
350− (
340+ (
351− toDescription category $
341+ toDescription category $
352− "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
342+ "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
353− ,
343+ ,
354− "But all the previous branches result in:"
344+ "But all the previous branches result in:"
355− ,
345+ ,
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."
361− --, problem
362− ]
351+ ]
363− )
352+ )
364− )
353+ )
365
354
366 CaseBranch index ->
355 CaseBranch index ->
367− if Index.toHuman index == 2 then
368− error "TODO 1st vs 2nd case branches"
369− else
370− Report.toCodeSnippet source region (Just exprRegion)
356+ Report.toCodeSnippet source region (Just exprRegion)
371− (
357+ (
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:"
374− ,
360+ ,
375− typeComparison localizer tipe expectedType
361+ typeComparison localizer tipe expectedType
376− (
362+ (
377− toDescription category $
363+ toDescription category $
378− "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
364+ "The " <> H.ordinalize (Index.toHuman index) <> " branch is"
379− ,
365+ ,
380− "But all the previous branches result in:"
366+ "But all the previous branches result in:"
381− ,
367+ ,
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."
387− --, problem
388− ]
373+ ]
389− )
374+ )
390− )
375+ )
391
376
392 CallArg maybeFuncName index ->
377 CallArg maybeFuncName index ->
393 let
378 let
@@ -508,7 +493,7 @@ toMismatchReport source localizer exprRegion category tipe expected =
508
493
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 _ _ ->
513 (
498 (
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?"
523 ]
508 ]
524− ++
525− case error "TODO closeNames" of
526− [] ->
527− []
528−
529− [name] ->
530− [ H.toFancyHint $
531− ["It","may","also","be","a","typo","in","the","record","itself."
532− ,"Perhaps","the",H.dullyellow name,"field","is","misspelled?"
533− ]
534− ]
535−
536− names ->
537− [ H.toFancyHint $
538− ["It","may","also","be","a","typo","in","the","record","itself."
539− ,"Perhaps","the"
540− ]
541− ++ H.commaSep "or" H.dullyellow names
542− ++ ["field","is","misspelled?"]
543− ]
544− )
545−
546− T.Lambda _ _ _ ->
547− (
548− H.reflow $
549− "I cannot access field `" <> N.toString field <> "` of this " <> whatever <> ":"
550− ,
551− H.stack
552− [ H.reflow $
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?"
556− ]
557 )
509 )
558
510
559 _ ->
511 _ ->
560 (
512 (
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!"
563 ,
515 ,
564 H.stack
516 H.stack
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
519+ , H.fillSep
520+ ["But","I","need","a","record","with","a",H.dullyellow (H.nameToDoc field),"field!"]
568 ]
521 ]
569 )
522 )
570
523
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 $
575 (
528 (
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:"
578 ,
531 ,
579− error "TODO record update field name typo"
532+ typeComparison localizer tipe expectedType
533+ (
534+ "The record you want to update has type:"
535+ ,
536+ "But you are saying it should have these fields:"
537+ ,
538+ [ H.reflow "Maybe there is some typo?"
539+ ]
540+ )
580 )
541 )
581
542
582 _ ->
543 _ ->
@@ -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:"
586 ,
547 ,
587 H.stack
548 H.stack
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!"
591 ]
552 ]
592 )
553 )
593
554
594 Destructure ->
555 Destructure ->
595− error "TODO Destructure"
556+ Report.toCodeSnippet source region Nothing
557+ (
558+ H.reflow $
559+ "I cannot destructure "
560+ ,
561+ typeComparison localizer tipe expectedType
562+ (
563+ toDescription category "You are defining"
564+ ,
565+ "But then trying to destructure it as:"
566+ ,
567+ []
568+ )
569+ )
596
570
597
571
598
572
@@ -618,15 +592,15 @@ opLeftToDocs localizer category op tipe expectedType =
618 case op of
592 case op of
619 "+"
593 "+"
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 []
623
597
624 "*"
598 "*"
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 []
627
601
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!"
641 ,
615 ,
642 H.stack
616 H.stack
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!"
647− {-
648− case category of
649− Call ->
650− "Maybe you gave " <> funcName <> " too many arguments already?"
651−
652− _ ->
653− []
654− -}
655 ]
620 ]
656 )
621 )
657
622
@@ -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 []
692
657
693 "*"
658 "*"
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 []
698
663
699 "-"
664 "-"
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 []
703
668
704 "^"
669 "^"
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 []
708
673
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
725 (
690 (
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:"
728 ,
693 ,
729 typeComparison localizer tipe expectedType
694 typeComparison localizer tipe expectedType
730 (
695 (
@@ -732,9 +697,7 @@ opRightToDocs localizer category op tipe expectedType =
732 ,
697 ,
733 "But (<|) is piping it a function that expects:"
698 "But (<|) is piping it a function that expects:"
734 ,
699 ,
735− [ "Maybe an argument is missing?"
736−-- , problem
737− ]
700+ []
738 )
701 )
739 )
702 )
740
703
@@ -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
745 (
708 (
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:"
748 ,
710 ,
749 typeComparison localizer argType expectedArgType
711 typeComparison localizer argType expectedArgType
750 (
712 (
751 "You are providing an argument of type:"
713 "You are providing an argument of type:"
752 ,
714 ,
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:"
754− {-
755− case maybeName of
756− Nothing ->
757− "But (|>) is piping it a function that expects the next argument to be:"
758−
759− Just (FuncName name) ->
760− "But (|>) is piping it to `" <> N.toString name <> "` which expects the next argument to be:"
761−
762− Just (OpName op) ->
763− "But (|>) is piping it to (" <> N.toString op <> ") which expects the next argument to be:"
764− -}
765 ,
716 ,
766− [ "Maybe an argument is missing?"
767−-- , problem
768− ]
717+ []
769 )
718 )
770 )
719 )
771
720
@@ -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!"
776 ,
725 ,
777 H.stack
726 H.stack
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
781− , error "TODO"
782− {-
783− case category of
784− Call ->
785− "Maybe you gave " <> funcName <> " too many arguments already?"
786−
787− _ ->
788− []
789− -}
790 ]
730 ]
791 )
731 )
792
732
@@ -802,12 +742,11 @@ opRightToDocs localizer category op tipe expectedType =
802 ,
742 ,
803 "But (" <> N.toString op <> ") needs the right argument to be:"
743 "But (" <> N.toString op <> ") needs the right argument to be:"
804 ,
744 ,
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!"
809 ]
749 ]
810− -}
811 )
750 )
812 )
751 )
813
752
@@ -853,11 +792,6 @@ isList tipe =
853 False
792 False
854
793
855
794
856−whatever :: String
857−whatever =
858− error "TODO whatever"
859−
860−
861
795
862-- BAD MATH
796-- BAD MATH
863
797
@@ -920,14 +854,14 @@ badStringAdd =
920 )
854 )
921
855
922
856
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 =
925 (
859 (
926 "I cannot do addition with lists:"
860 "I cannot do addition with lists:"
927 ,
861 ,
928 H.stack
862 H.stack
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 =
939 )
873 )
940
874
941
875
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
945 [
879 [
946 H.toFancyHint
880 H.toFancyHint
947 [ "Maybe", "you", "want"
881 [ "Maybe", "you", "want"
@@ -951,21 +885,20 @@ badListMul localizer direction tipe =
951 ]
885 ]
952
886
953
887
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 =
956 (
890 (
957 H.reflow $
891 H.reflow $
958 operation ++ " does not work with this value:"
892 operation ++ " does not work with this value:"
959 ,
893 ,
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."
967 ]
901 ]
968− , error "TODO check for missing arguments"
969 ]
902 ]
970 ++ otherHints
903 ++ otherHints
971 )
904 )
@@ -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?"
1138 ]
1071 ]
1139−-- else
1140−-- error "TODO detect problems here instead?"
1141 )
1072 )
1142 )
1073 )
1143
1074