aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-03-09 18:18:13 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-03-09 18:18:13 -0400
commit806e0d0554a8f619cb5b835e535f5f1022543c1a (patch)
tree404415db1ce08273ac778f44d9d83e5d6dcc7bf4
parent7fbba1b7901fcd9b9363132b99ada636cddbfad9 (diff)
Make it a compiler error to have an always-aborting function whose
return type is Void
-rw-r--r--compile.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/compile.c b/compile.c
index 442886a9..19388008 100644
--- a/compile.c
+++ b/compile.c
@@ -4113,8 +4113,12 @@ CORD compile_function(env_t *env, ast_t *ast, CORD *staticdefs)
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);
+ } else if (ret_t->tag == VoidType) {
+ if (body_type->tag == AbortType)
+ code_err(ast, "This function will always abort before it reaches the end, but it's declared as having a Void return. It should be declared as an Abort return instead.");
+ } else {
+ if (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);