aboutsummaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-03-09 17:52:48 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-03-09 17:52:48 -0400
commit94ed28b4d19692cccc9da7640931ed45d31e47c6 (patch)
tree1c57de73ec25e256d63250551c27cafdba1f63d7 /compile.c
parent6abd4e80244a7fa73a7213101b1d61e4df1b6689 (diff)
Add better typechecking for Abort (and add `Abort` as a user-reachable
type) and check for unreachable code
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/compile.c b/compile.c
index 30e20e5b..3f7380e7 100644
--- a/compile.c
+++ b/compile.c
@@ -4108,8 +4108,12 @@ CORD compile_function(env_t *env, ast_t *ast, CORD *staticdefs)
body_scope->fn_ret = ret_t;
type_t *body_type = get_type(body_scope, fndef->body);
- if (ret_t->tag != VoidType && ret_t->tag != AbortType && body_type->tag != AbortType && body_type->tag != ReturnType)
+ if (ret_t->tag == AbortType) {
+ if (body_type->tag != AbortType)
+ code_err(ast, "This function can reach the end without aborting!");
+ } else if (ret_t->tag != VoidType && body_type->tag != ReturnType) {
code_err(ast, "This function can reach the end without returning a %T value!", ret_t);
+ }
CORD body = compile_statement(body_scope, fndef->body);
if (streq(raw_name, "main"))