From effec3a1f61017698946cbc4acbdec7355b6857b Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 13 Oct 2022 13:34:54 +0200 Subject: [PATCH] Fix of bug where missing return wasn't detected. --- src/compiler/sema_expr.c | 2 +- src/version.h | 2 +- test/test_suite/macros/macro_missing_return.c3 | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 test/test_suite/macros/macro_missing_return.c3 diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 7e76d6ae6..5d7e536a9 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -1748,7 +1748,7 @@ bool sema_expr_analyse_macro_call(SemaContext *context, Expr *call_expr, Expr *s params = macro_context.macro_params; bool is_no_return = decl->func_decl.signature.attrs.noreturn; - if (!vec_size(macro_context.returns)) + if (!vec_size(macro_context.returns) || !macro_context.active_scope.jump_end) { if (rtype && rtype != type_void) { diff --git a/src/version.h b/src/version.h index 1fb56b042..e209179f9 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.3.83" \ No newline at end of file +#define COMPILER_VERSION "0.3.84" \ No newline at end of file diff --git a/test/test_suite/macros/macro_missing_return.c3 b/test/test_suite/macros/macro_missing_return.c3 new file mode 100644 index 000000000..af0f4e982 --- /dev/null +++ b/test/test_suite/macros/macro_missing_return.c3 @@ -0,0 +1,12 @@ +module test; +import std::io; + +macro int foo(int y) // #error: Missing return +{ + if (y > 5) return y; +} + +fn void main() +{ + int x = foo(3); +} \ No newline at end of file