handle non-void fn without return
This commit is contained in:
parent
16ee21d6d0
commit
c5c2fd2d1c
2 changed files with 7 additions and 4 deletions
10
semantics.ml
10
semantics.ml
|
@ -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
|
||||
|
|
1
tests/16_err-no-return-int-fn.test
Normal file
1
tests/16_err-no-return-int-fn.test
Normal file
|
@ -0,0 +1 @@
|
|||
int main () {} # Warning on line 1 col 4: Non-void function without return.
|
Reference in a new issue