From 8b47317ec7299091c0120c89d6ae15c4e6ef6354 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Thu, 3 Jul 2025 13:11:12 +0200 Subject: [PATCH] Fix issue with labelled break inside of a $switch. --- releasenotes.md | 1 + src/compiler/sema_stmts.c | 5 +++-- .../compile_time/compile_time_with_break.c3t | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/test_suite/compile_time/compile_time_with_break.c3t diff --git a/releasenotes.md b/releasenotes.md index 5357ad768..9987eb259 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -17,6 +17,7 @@ - Switch case with const non-int / enum would be treated as ints and crash. #2263 - Missing bounds check on upper bound with const ranges `foo[1:3]`. - Check up the hierarchy when considering if an interface cast is valid #2267. +- Fix issue with labelled break inside of a $switch. ### Stdlib changes diff --git a/src/compiler/sema_stmts.c b/src/compiler/sema_stmts.c index ef2264995..4124ffa73 100644 --- a/src/compiler/sema_stmts.c +++ b/src/compiler/sema_stmts.c @@ -2224,9 +2224,10 @@ static inline bool sema_analyse_then_overwrite(SemaContext *context, Ast *statem return true; } Ast *last = NULL; + statement->ast_kind = AST_NOP_STMT; AstId next = statement->next; - *statement = *astptr(replacement); - AstId current = astid(statement); + statement->next = replacement; + AstId current = replacement; ASSERT(current); while (current) { diff --git a/test/test_suite/compile_time/compile_time_with_break.c3t b/test/test_suite/compile_time/compile_time_with_break.c3t new file mode 100644 index 000000000..8405430c5 --- /dev/null +++ b/test/test_suite/compile_time/compile_time_with_break.c3t @@ -0,0 +1,17 @@ +enum Test +{ + FOO, +} + +fn int main() +{ + int v; + $switch (Test.FOO): + $case FOO: + if START: (v < 5) + { + if (v > 3) break START; + } + $endswitch + return 0; +} \ No newline at end of file