From 5ed4f9519f6d7fe158e8fe73f5f7e163fa615040 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 30 Dec 2025 16:06:28 +0100 Subject: [PATCH] - `x'1234' +++ (ichar[1]) { 'A' }` would fail due to missing const folding. --- releasenotes.md | 1 + src/compiler/sema_const.c | 4 ++++ test/test_suite/compile_time/concat_convert.c3 | 5 +++++ 3 files changed, 10 insertions(+) create mode 100644 test/test_suite/compile_time/concat_convert.c3 diff --git a/releasenotes.md b/releasenotes.md index c1f54cac9..18f20f55c 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -42,6 +42,7 @@ - Assert when encountering a malformed module alias. - Assert when encountering a test function with raw vaarg parameters. - `foo.x` was not always handled correctly when `foo` was optional. +- `x'1234' +++ (ichar[1]) { 'A' }` would fail due to missing const folding. ### Stdlib changes - Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads. diff --git a/src/compiler/sema_const.c b/src/compiler/sema_const.c index 0adea99f9..40bffc232 100644 --- a/src/compiler/sema_const.c +++ b/src/compiler/sema_const.c @@ -187,6 +187,10 @@ static bool sema_concat_bytes_and_other(SemaContext *context, Expr *expr, Expr * case CONST_SLICE: case CONST_INITIALIZER: if (!cast_implicit(context, right, type_get_inferred_array(indexed), false)) return false; + if (!sema_cast_const(right)) + { + RETURN_SEMA_ERROR(right, "Could not concatenate with the right hand side."); + } expr_contract_array(&right->const_expr, left->const_expr.const_kind); goto RETRY; } diff --git a/test/test_suite/compile_time/concat_convert.c3 b/test/test_suite/compile_time/concat_convert.c3 new file mode 100644 index 000000000..910e0d888 --- /dev/null +++ b/test/test_suite/compile_time/concat_convert.c3 @@ -0,0 +1,5 @@ +fn int main() +{ + const A = x'1234' +++ (ichar[1]) { 'A' }; + return 0; +}