X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;ds=sidebyside;f=sem.icl;h=f3d28c29f68dde153b023774d68d33b3ec6e7d45;hb=d0e8cca079e8b36453b3eeee66b25681e5423f18;hp=06200b1bd2ecdb2c8bd71e28559ea91f68e1caf1;hpb=76d648be58ffa5c21cb9a53fb0232ab16d9f81b4;p=cc1516.git diff --git a/sem.icl b/sem.icl index 06200b1..f3d28c2 100644 --- a/sem.icl +++ b/sem.icl @@ -70,7 +70,8 @@ semFunDecl fd=:(FunDecl p f args mt vds stmts) = inferReturnType :: [Stmt] -> Env Type inferReturnType [] = pure VoidType -inferReturnType [ReturnStmt (Just t):rest] = typeExpr t +inferReturnType [ReturnStmt (Just t):rest] = typeExpr t + >>= \tx->inferReturnType rest >>= \ty->unify tx ty inferReturnType [ReturnStmt _:rest] = pure VoidType inferReturnType [_:rest] = inferReturnType rest @@ -200,6 +201,8 @@ instance unify Type where unify (ListType t1) (ListType t2) = unify t1 t2 >>| (pure $ ListType t1) unify (ta1 ->> ta2) (tb1 ->> tb2) = unify ta1 tb1 >>= \ta-> unify ta2 tb2 >>= \tb-> pure (ta ->> tb) + unify VoidType t = pure t + unify t VoidType = pure t unify VoidType VoidType = pure VoidType unify t1 t2 = liftT $ Left $ UnifyError zero t1 t2