From 0118394558cef840c47952c1dd997a235c279ada Mon Sep 17 00:00:00 2001 From: "Juan J. Martinez" Date: Sun, 14 Aug 2022 17:38:02 +0100 Subject: Missing case --- src/Compiler.hs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/Compiler.hs b/src/Compiler.hs index 62be364..602490e 100644 --- a/src/Compiler.hs +++ b/src/Compiler.hs @@ -59,10 +59,15 @@ typecheckCall args params -- there was an error in on argument return $ Nothing +showMaybet :: Maybe A.Type -> String +showMaybet Nothing = "()" +showMaybet (Just t) = show t + -- | @typecheckReturn value fret@ resolves @value@ and compares it with @fret@, -- returning a string decribing an error or Nothing in case of a type match. typecheckReturn :: Maybe A.Expr -> Maybe A.Type -> State CompState (Maybe String) typecheckReturn Nothing Nothing = return $ Nothing +typecheckReturn Nothing fret = return $ Just $ "invalid return value:\n unexpected ()\n expecting " ++ showMaybet fret typecheckReturn (Just value) fret = do r <- compile value case r of @@ -71,10 +76,6 @@ typecheckReturn (Just value) fret = do then return $ Nothing else return $ Just $ "invalid return value:\n unexpected " ++ showMaybet r ++ "\n expecting " ++ showMaybet fret Left _ -> return $ Nothing -- error resolving return value - where - showMaybet :: Maybe A.Type -> String - showMaybet Nothing = "()" - showMaybet (Just t) = show t compile :: A.Expr -> State CompState CompResult compile x = do -- cgit v1.2.3