1
0
forked from GitHub/gf-core

Add clarification to "expected foo, inferred bar" type of error msgs

This commit is contained in:
Inari Listenmaa
2020-06-04 19:57:10 +02:00
parent a4e3bce6bb
commit c0714b7d33

View File

@@ -132,7 +132,7 @@ inferLType gr g trm = case trm of
let term = ppTerm Unqualified 0 f let term = ppTerm Unqualified 0 f
funName = pp . head . words .render $ term funName = pp . head . words .render $ term
in checkError ("A function type is expected for" <+> term <+> "instead of type" <+> ppType fty $$ in checkError ("A function type is expected for" <+> term <+> "instead of type" <+> ppType fty $$
"\n Maybe you gave too many arguments to" <+> funName) "\n ** Maybe you gave too many arguments to" <+> funName <+> "\n")
S f x -> do S f x -> do
(f', fty) <- inferLType gr g f (f', fty) <- inferLType gr g f
@@ -432,7 +432,9 @@ checkLType gr g trm typ0 = do
else do b' <- checkIn (pp "abs") $ substituteLType [(bt',z,Vr x)] b else do b' <- checkIn (pp "abs") $ substituteLType [(bt',z,Vr x)] b
checkLType gr ((bt,x,a):g) c b' checkLType gr ((bt,x,a):g) c b'
return $ (Abs bt x c', Prod bt' z a b') return $ (Abs bt x c', Prod bt' z a b')
_ -> checkError $ "function type expected instead of" <+> ppType typ _ -> checkError $ "function type expected instead of" <+> ppType typ $$
"\n ** Double-check that the type signature of the operation" $$
"matches the number of arguments given to it.\n"
App f a -> do App f a -> do
over <- getOverload gr g (Just typ) trm over <- getOverload gr g (Just typ) trm
@@ -652,11 +654,11 @@ checkEqLType gr g t u trm = do
(0,0) -> pp "" -- None of the types is a function (0,0) -> pp "" -- None of the types is a function
_ -> if expectedType `isLessApplied` inferredType _ -> if expectedType `isLessApplied` inferredType
then "Maybe you gave too few arguments to" <+> funName then "Maybe you gave too few arguments to" <+> funName
else "Maybe you gave too many arguments to" <+> funName else pp "Double-check that type signature and number of arguments match."
in checkError $ s <+> "type of" <+> term $$ in checkError $ s <+> "type of" <+> term $$
"expected:" <+> expectedType $$ -- ppqType t u $$ "expected:" <+> expectedType $$ -- ppqType t u $$
"inferred:" <+> inferredType $$ -- ppqType u t "inferred:" <+> inferredType $$ -- ppqType u t
"\n " <+> helpfulMsg "\n **" <+> helpfulMsg <+> "\n"
where where
-- count the number of arrows in the prettyprinted term -- count the number of arrows in the prettyprinted term
arrows :: Doc -> Int arrows :: Doc -> Int