From 8151305701dc5db789a3d7ad1a476c3764a68604 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 29 Jul 2025 20:50:32 +0200 Subject: [PATCH] Fix so that rethrow is detected as well. --- src/compiler/sema_expr.c | 4 ++++ test/test_suite/asm/naked_rethrow.c3 | 13 +++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 test/test_suite/asm/naked_rethrow.c3 diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 52ba3148c..8bb90ecf5 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -9197,6 +9197,10 @@ static inline bool sema_expr_analyse_rethrow(SemaContext *context, Expr *expr, T context->call_env.current_function->name, type_quoted_error_string(context->rtype)); } + if (context->call_env.is_naked_fn) + { + RETURN_SEMA_ERROR(expr, "Rethrow is not allowed in a '@naked' function."); + } } return true; } diff --git a/test/test_suite/asm/naked_rethrow.c3 b/test/test_suite/asm/naked_rethrow.c3 new file mode 100644 index 000000000..72da4b570 --- /dev/null +++ b/test/test_suite/asm/naked_rethrow.c3 @@ -0,0 +1,13 @@ +import std; +fn void main() +{ + (void)test(); +} + + +fn ulong? test() @naked @noinline +{ + int? z; + z!; // #error: Rethrow is not allowed in a '@naked' function + unreachable(); +} \ No newline at end of file