From c3d2b2824c76711fdd9ab30865dc2369c1e31f59 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sat, 31 May 2025 17:35:29 +0200 Subject: [PATCH] Bug using `#foo` arguments with `$defined` #2173 --- releasenotes.md | 1 + src/compiler/sema_expr.c | 4 ++-- .../compile_time_introspection/defined_hash.c3 | 10 ++++++++++ 3 files changed, 13 insertions(+), 2 deletions(-) create mode 100644 test/test_suite/compile_time_introspection/defined_hash.c3 diff --git a/releasenotes.md b/releasenotes.md index ef7f0bcf3..cae057f14 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -58,6 +58,7 @@ - Check pointer/slice/etc on `[out]` and `&` params. #2156. - Compiler didn't check foreach over flexible array member, and folding a flexible array member was allowed #2164. - Too strict project view #2163. +- Bug using `#foo` arguments with `$defined` #2173 ### Stdlib changes - Added `String.quick_ztr` and `String.is_zstr` diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index 8fd37df24..01bf34128 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -9661,10 +9661,10 @@ static inline bool sema_expr_analyse_ct_defined(SemaContext *context, Expr *expr { case EXPR_OTHER_CONTEXT: active_context->call_env.in_no_eval = in_no_eval; - active_context = expr->expr_other_context.context; + active_context = main_expr->expr_other_context.context; in_no_eval = active_context->call_env.in_no_eval; active_context->call_env.in_no_eval = true; - main_expr = expr->expr_other_context.inner; + main_expr = main_expr->expr_other_context.inner; goto RETRY; case EXPR_ACCESS_UNRESOLVED: if (!sema_expr_analyse_access(active_context, main_expr, &failed, CHECK_VALUE, false)) diff --git a/test/test_suite/compile_time_introspection/defined_hash.c3 b/test/test_suite/compile_time_introspection/defined_hash.c3 new file mode 100644 index 000000000..f1fcdc6e1 --- /dev/null +++ b/test/test_suite/compile_time_introspection/defined_hash.c3 @@ -0,0 +1,10 @@ +macro @test(#a) +{ + $defined(#a); +} + +fn int main() +{ + @test(0); + return 0; +} \ No newline at end of file