]> ruin.nu Git - proglang.git/commitdiff
rejects functions without return statements
authorMichael Andreen <harv@ruin.nu>
Sat, 11 Mar 2006 20:00:34 +0000 (20:00 +0000)
committerMichael Andreen <harv@ruin.nu>
Sat, 11 Mar 2006 20:00:34 +0000 (20:00 +0000)
Typecheck.hs
examples/typeerror-funcnoreturn [new file with mode: 0644]

index e2aa3d7182d61eef64d28b462efb2f3d9efde328..5c70ccf02c04118b27f297e854d887be05c58a13 100644 (file)
@@ -117,6 +117,9 @@ typeCheckFunction (Func t i d s) = do
        state <- get
        modify (\s -> s{variables=[empty], function=i})
        mapM (\(Decl t i) -> addVariable i t) d
+       case last s of
+               (SReturn _) -> return ()
+               _ -> fail $ "Function "++show i++" doesn't end with return statement"
        mapM typeCheckStm s
        put state
 
diff --git a/examples/typeerror-funcnoreturn b/examples/typeerror-funcnoreturn
new file mode 100644 (file)
index 0000000..1fb75eb
--- /dev/null
@@ -0,0 +1,3 @@
+int a(){
+       int a;
+}