From 1e11b6c442bc25e4135a692d728cd20db4fe1cd6 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 20 Jan 2026 23:58:45 +0100 Subject: [PATCH] Inferring the size of a slice with an inner inferred array using {} isn't detected as error #2783 --- releasenotes.md | 1 + src/compiler/sema_initializers.c | 4 ++++ test/test_suite/slices/slice_infer_inner_empty_err.c3 | 5 +++++ 3 files changed, 10 insertions(+) create mode 100644 test/test_suite/slices/slice_infer_inner_empty_err.c3 diff --git a/releasenotes.md b/releasenotes.md index 4e9e862eb..794380d9c 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -26,6 +26,7 @@ - $typeof untyped list crashes when trying to create typeid from it. #2779 - Recursive constant definition not properly detected, leading to assert #2780 - Failed to reject void compile time variables, leading to crash. #2781 +- Inferring the size of a slice with an inner inferred array using {} isn't detected as error #2783 ### Fixes - Regression with npot vector in struct triggering an assert #2219. diff --git a/src/compiler/sema_initializers.c b/src/compiler/sema_initializers.c index 5b28b84b2..d94436ee7 100644 --- a/src/compiler/sema_initializers.c +++ b/src/compiler/sema_initializers.c @@ -881,6 +881,10 @@ bool sema_expr_analyse_initializer_list(SemaContext *context, Type *to, Expr *ex { if (is_zero_init) { + if (type_len_is_inferred(flattened->array.base)) + { + RETURN_SEMA_ERROR(expr, "Inferring the slice inner type from an empty initializer is not possible."); + } expr_rewrite_const_empty_slice(expr, to); return true; } diff --git a/test/test_suite/slices/slice_infer_inner_empty_err.c3 b/test/test_suite/slices/slice_infer_inner_empty_err.c3 new file mode 100644 index 000000000..1413db69c --- /dev/null +++ b/test/test_suite/slices/slice_infer_inner_empty_err.c3 @@ -0,0 +1,5 @@ +fn int main() +{ + int [*][] y = { }; // #error: Inferring the slice inner type from an empty initializer is not possible + return 0; +} \ No newline at end of file