on master help sign in
Provide hint for "not enough args"
22bbeaeEvan Czaplicki
src/Reporting/Error/Type.hs+9
@@ -39,6 +39,7 @@ data Reason
39 = MessyFields [String] [String]
39 = MessyFields [String] [String]
40 | IntFloat
40 | IntFloat
41 | TooLongComparableTuple Int
41 | TooLongComparableTuple Int
42+ | MissingArgs Int
42 | BadVar (Maybe VarType) (Maybe VarType)
43 | BadVar (Maybe VarType) (Maybe VarType)
43
44
44
45
@@ -591,6 +592,9 @@ flipReason reason =
591 TooLongComparableTuple len ->
592 TooLongComparableTuple len ->
592 TooLongComparableTuple len
593 TooLongComparableTuple len
593
594
595+ MissingArgs num ->
596+ MissingArgs num
597+
594 BadVar left right ->
598 BadVar left right ->
595 BadVar right left
599 BadVar right left
596
600
@@ -618,6 +622,11 @@ reasonToString reason =
618 "Although tuples are comparable, this is currently only supported\
622 "Although tuples are comparable, this is currently only supported\
619 \ for tuples with 6 or fewer entries, not " ++ show len ++ "."
623 \ for tuples with 6 or fewer entries, not " ++ show len ++ "."
620
624
625+ MissingArgs num ->
626+ go $
627+ "It looks like a function needs " ++ show num ++ " more "
628+ ++ (if num == 1 then "argument" else "arguments") ++ "."
629+
621 BadVar (Just Comparable) _ ->
630 BadVar (Just Comparable) _ ->
622 go "Only ints, floats, chars, strings, lists, and tuples are comparable."
631 go "Only ints, floats, chars, strings, lists, and tuples are comparable."
623
632
src/Type/Unify.hs+23−1
@@ -76,7 +76,18 @@ newtype Mismatch =
76
76
77
77
78mismatch :: Context -> Maybe Error.Reason -> Unify a
78mismatch :: Context -> Maybe Error.Reason -> Unify a
79−mismatch (Context orientation _ _ _ _) maybeReason =
79+mismatch (Context orientation var1 _ var2 _) maybeReason =
80+ do numArgs1 <- liftIO $ countArgs var1
81+ numArgs2 <- liftIO $ countArgs var2
82+ mismatchHelp orientation $
83+ if numArgs1 == numArgs2 then
84+ maybeReason
85+ else
86+ Just (Error.MissingArgs (abs (numArgs2 - numArgs1)))
87+
88+
89+mismatchHelp :: Orientation -> Maybe Error.Reason -> Unify a
90+mismatchHelp orientation maybeReason =
80 throwError $ Mismatch $
91 throwError $ Mismatch $
81 case orientation of
92 case orientation of
82 ExpectedActual ->
93 ExpectedActual ->
@@ -443,6 +454,17 @@ collectAppsHelp args content =
443 return Other
454 return Other
444
455
445
456
457+countArgs :: Variable -> IO Int
458+countArgs variable =
459+ do content <- getContent variable
460+ case content of
461+ Structure (Fun1 _ returnType) ->
462+ (+1) <$> countArgs returnType
463+
464+ _ ->
465+ return 0
466+
467+
446getContent :: Variable -> IO Content
468getContent :: Variable -> IO Content
447getContent variable =
469getContent variable =
448 _content <$> UF.descriptor variable
470 _content <$> UF.descriptor variable