From 94ed28b4d19692cccc9da7640931ed45d31e47c6 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 9 Mar 2025 17:52:48 -0400 Subject: Add better typechecking for Abort (and add `Abort` as a user-reachable type) and check for unreachable code --- compile.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'compile.c') 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")) -- cgit v1.2.3