Recursive constant definition not properly detected, leading to assert #2780

This commit is contained in:
Christoffer Lerno
2026-01-20 18:28:13 +01:00
parent 888657cc97
commit 52afbdbde9
3 changed files with 9 additions and 0 deletions

View File

@@ -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.

View File

@@ -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))

View File

@@ -0,0 +1,4 @@
fn int main()
{
const A = x'1234' +++ (ichar[A]); // #error: The evaluation of this expression is recursive.
}