From 9b3b4ae8be737e838bfe3443fe1bbf40ff878c71 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 3 Jul 2025 22:20:14 +0200 Subject: [PATCH] `$for` ct-state not properly popped. --- releasenotes.md | 1 + src/compiler/sema_stmts.c | 1 + test/test_suite/compile_time/pop_ct_for.c3 | 16 ++++++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 test/test_suite/compile_time/pop_ct_for.c3 diff --git a/releasenotes.md b/releasenotes.md index 72b606a5f..3c2da1510 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -19,6 +19,7 @@ - Check up the hierarchy when considering if an interface cast is valid #2267. - Fix issue with labelled break inside of a $switch. - Non-const macros may not return untyped lists. +- `$for` ct-state not properly popped. ### Stdlib changes diff --git a/src/compiler/sema_stmts.c b/src/compiler/sema_stmts.c index 4124ffa73..4a7cb77f0 100644 --- a/src/compiler/sema_stmts.c +++ b/src/compiler/sema_stmts.c @@ -3048,6 +3048,7 @@ static inline bool sema_analyse_ct_for_stmt(SemaContext *context, Ast *statement // Analysis is done turn the generated statements into a compound statement for lowering. statement->ast_kind = AST_CT_COMPOUND_STMT; statement->ct_compound_stmt = start; + sema_context_pop_ct_stack(context, for_context); return true; FAILED: sema_context_pop_ct_stack(context, for_context); diff --git a/test/test_suite/compile_time/pop_ct_for.c3 b/test/test_suite/compile_time/pop_ct_for.c3 new file mode 100644 index 000000000..d8a69aa8b --- /dev/null +++ b/test/test_suite/compile_time/pop_ct_for.c3 @@ -0,0 +1,16 @@ +fn int main() +{ + $for var $i = 1; $i < 8; ++$i : + $endfor + + $for var $i = 0; $i < 8; ++$i : + $endfor + + const int[*] ABC = { 1, 2, 3 }; + $foreach $i, $val : ABC: + $endforeach + $foreach $i, $val : ABC: + $endforeach + + return 0; +} \ No newline at end of file