handle non-void fn without return

This commit is contained in:
Mylloon 2022-12-10 16:36:41 +01:00
parent 16ee21d6d0
commit c5c2fd2d1c
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
2 changed files with 7 additions and 4 deletions

View file

@ -70,14 +70,16 @@ let analyze_instr env ua ret_t = function
Return ae, env, []
;;
let rec analyze_block env ua ret_t = function
| [] -> [], ua
let rec analyze_block env ua ret_t pos = function
| [] ->
if ret_t != Void_t then warn "Non-void function without return" pos;
[], ua
| instr :: new_block ->
let new_instr, new_env, ua1 = analyze_instr env ua ret_t instr in
(match new_instr with
| Return _ -> [ new_instr ], ua1
| _ ->
let new_block, ua2 = analyze_block new_env ua1 ret_t new_block in
let new_block, ua2 = analyze_block new_env ua1 ret_t pos new_block in
new_instr :: new_block, ua2)
;;
@ -89,7 +91,7 @@ let analyze_func env ua = function
(match h with
| Syntax.Arg a -> add_args (Env.add a.name a.type_t env) t)
in
let block, _ = analyze_block (add_args env f.args) ua f.type_t f.code in
let block, _ = analyze_block (add_args env f.args) ua f.type_t f.pos f.code in
( Func
( f.func
, List.map

View file

@ -0,0 +1 @@
int main () {} # Warning on line 1 col 4: Non-void function without return.