ox

The Ox programming language, compiler and tools (WIP)
Log | Files | Refs | README | LICENSE

commit 79790dc4e33acdca7fc70ca35a154cca55b8b9d0
parent 710ef7e5f77568afc7e2e5bb659c11aa0bef99ef
Author: citbl <citbl@citbl.org>
Date:   Sun, 16 Nov 2025 19:09:43 +1000

handle lack of expression in return statements

Diffstat:
M.zed/debug.json | 2+-
Msrc/gen/gen.c | 9+++++++--
Atests/ex-return-early.ox | 9+++++++++
Atests/ex-return-empty.ox | 18++++++++++++++++++
4 files changed, 35 insertions(+), 3 deletions(-)

diff --git a/.zed/debug.json b/.zed/debug.json @@ -11,7 +11,7 @@ "cwd": "$ZED_WORKTREE_ROOT" }, "program": "$ZED_WORKTREE_ROOT/oxc", - "args": ["$ZED_WORKTREE_ROOT/tests/ex-return-int.ox"], + "args": ["$ZED_WORKTREE_ROOT/tests/ex-return-empty.ox"], "request": "launch", "adapter": "CodeLLDB" } diff --git a/src/gen/gen.c b/src/gen/gen.c @@ -907,8 +907,13 @@ build_statement(Gen* gen, Node* node) gcc_jit_location* loc = loc_from_node(gen, node); switch (node->type) { case NODE_RETURN: { - gcc_jit_rvalue* rv = handle_expr(gen, node->data.ret.expr); - gcc_jit_block_end_with_return(gen->curr_block, loc, rv); + Node* return_expr = node->data.ret.expr; + if (return_expr) { + gcc_jit_rvalue* rv = handle_expr(gen, return_expr); + gcc_jit_block_end_with_return(gen->curr_block, loc, rv); + } else { + gcc_jit_block_end_with_void_return(gen->curr_block, loc); + } gen->curr_block = NULL; // important return true; // we end the block here } diff --git a/tests/ex-return-early.ox b/tests/ex-return-early.ox @@ -0,0 +1,9 @@ +int example() { + print("we should only print one line"); + return 1; + print("DEAD CODE"); +} + +void main() { + example(); +} diff --git a/tests/ex-return-empty.ox b/tests/ex-return-empty.ox @@ -0,0 +1,18 @@ +void returnnothing() { + print("I will return nothing"); + return; +} + + +void main() { + print("calling return nothing:"); + returnnothing(); + return; + return; + return; + return; + return; + return; + return; + return; +}