diff options
Diffstat (limited to 'check.hs')
-rw-r--r-- | check.hs | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -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 |