summaryrefslogtreecommitdiff
path: root/check.hs
diff options
context:
space:
mode:
Diffstat (limited to 'check.hs')
-rw-r--r--check.hs9
1 files changed, 6 insertions, 3 deletions
diff --git a/check.hs b/check.hs
index 88b20a9..a29f18b 100644
--- a/check.hs
+++ b/check.hs
@@ -123,11 +123,13 @@ typeCheck (Program decls) = Program <$> mapM (goD topLevelNames) decls
re <- goE names e
(_, rs) <- goS frt names s
return (names, StWhile re rs)
- goS frt names (StReturn e) = do
+ goS TypeVoid names (StReturn Nothing) = return (names, StReturn Nothing)
+ goS _ _ (StReturn Nothing) = Left $ "Non-void function should return a value"
+ goS frt names (StReturn (Just e)) = do
re <- goE names e
let (Just extype) = exTypeOf re
if canConvert extype frt
- then return (names, StReturn re)
+ then return (names, StReturn (Just re))
else Left $ "Cannot convert type '" ++ pshow extype ++ "' to '"
++ pshow frt ++ "' in return statement"
@@ -370,7 +372,8 @@ mapProgram prog mapper = goP prog
re <- goE e
rs <- goS s
h_s $ StWhile re rs
- goS (StReturn e) = goE e >>= (h_s . StReturn)
+ goS (StReturn Nothing) = h_s (StReturn Nothing)
+ goS (StReturn (Just e)) = goE e >>= (h_s . StReturn . Just)
goL :: MapperHandler Literal
goL l@(LitString _) = h_l l