From 52afbdbde94aa55001894a4a7f55df1a1aa5799d Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 20 Jan 2026 18:28:13 +0100 Subject: [PATCH] Recursive constant definition not properly detected, leading to assert #2780 --- releasenotes.md | 1 + src/compiler/sema_expr.c | 4 ++++ test/test_suite/constants/recursive_constant.c3 | 4 ++++ 3 files changed, 9 insertions(+) create mode 100644 test/test_suite/constants/recursive_constant.c3 diff --git a/releasenotes.md b/releasenotes.md index 9a2866c3e..ac1a1bffa 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -24,6 +24,7 @@ - Second value in switch range not checked properly, causing an error on non-const values. #2777 - Broken cast from fault to array pointer #2778. - $typeof untyped list crashes when trying to create typeid from it. #2779 +- Recursive constant definition not properly detected, leading to assert #2780 ### Fixes - Regression with npot vector in struct triggering an assert #2219. diff --git a/src/compiler/sema_expr.c b/src/compiler/sema_expr.c index a14680bc3..e0e03f48c 100644 --- a/src/compiler/sema_expr.c +++ b/src/compiler/sema_expr.c @@ -1312,6 +1312,10 @@ static inline bool sema_expr_analyse_identifier(SemaContext *context, Type *to, case VARDECL_CONST: if (!decl->type) { + if (decl->var.init_expr->resolve_status == RESOLVE_RUNNING) + { + RETURN_SEMA_ERROR(decl->var.init_expr, "The evaluation of this expression is recursive."); + } Expr *copy = copy_expr_single(decl->var.init_expr); if (!sema_analyse_expr_rvalue(context, copy)) return false; if (!expr_is_runtime_const(copy)) diff --git a/test/test_suite/constants/recursive_constant.c3 b/test/test_suite/constants/recursive_constant.c3 new file mode 100644 index 000000000..b7e623b44 --- /dev/null +++ b/test/test_suite/constants/recursive_constant.c3 @@ -0,0 +1,4 @@ +fn int main() +{ + const A = x'1234' +++ (ichar[A]); // #error: The evaluation of this expression is recursive. +} \ No newline at end of file