From 0b9b49673eaee836c5c10b63ee718589a1793b6a Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 20 Jan 2026 00:04:18 +0100 Subject: [PATCH] - Empty struct after `@if` processing was not detected, causing a crash instead of an error. - Comparing an uint and int[<4>] was incorrectly assumed to be uint compared to int, causing a crash instead of an error. - When an `int[*][6]` was given too few values, the compiler would assert instead of giving an error. --- releasenotes.md | 1 + src/compiler/sema_casts.c | 4 ++++ test/test_suite/arrays/inferred_array_slice_fail.c3 | 11 +++++++++++ 3 files changed, 16 insertions(+) create mode 100644 test/test_suite/arrays/inferred_array_slice_fail.c3 diff --git a/releasenotes.md b/releasenotes.md index 25480875d..e5f7f0b02 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -84,6 +84,7 @@ - Empty struct after `@if` processing was not detected, causing a crash instead of an error. #2771 - Comparing an uint and int[<4>] was incorrectly assumed to be uint compared to int, causing a crash instead of an error. #2771 - When an `int[*][6]` was given too few values, the compiler would assert instead of giving an error. #2771 +- Inferring length from a slice was accidentally not an error. ### 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_casts.c b/src/compiler/sema_casts.c index ef98728b6..e8746bdac 100644 --- a/src/compiler/sema_casts.c +++ b/src/compiler/sema_casts.c @@ -1193,6 +1193,10 @@ static bool rule_slice_to_infer(CastContext *cc, bool is_explicit, bool is_silen static bool rule_vecarr_to_infer(CastContext *cc, bool is_explicit, bool is_silent) { Type *new_type = type_infer_len_from_actual_type(cc->to, cc->from); + if (type_is_inferred(new_type)) + { + return sema_cast_error(cc, false, is_silent); + } cast_context_set_to(cc, new_type); return cast_is_allowed(cc, is_explicit, is_silent); } diff --git a/test/test_suite/arrays/inferred_array_slice_fail.c3 b/test/test_suite/arrays/inferred_array_slice_fail.c3 new file mode 100644 index 000000000..b7ccef334 --- /dev/null +++ b/test/test_suite/arrays/inferred_array_slice_fail.c3 @@ -0,0 +1,11 @@ +import std; +macro test(int[*][1] a) { + var b = a; +} + +fn int main() +{ + int[][1] b; + test(b); // #error: It is not possible to cast 'int[][1]' to 'int[*][1]' + return 12; +} \ No newline at end of file