From c1e3cfaacc93885aa59ec891433b2ef56969973b Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Tue, 27 Jan 2026 23:36:00 +0100 Subject: [PATCH] - Crash when trying to create a const zero untyped list #2847 --- releasenotes.md | 1 + src/compiler/expr.c | 6 +++++- test/test_suite/macros/typeof_untyped_list_zero.c3t | 4 ++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 test/test_suite/macros/typeof_untyped_list_zero.c3t diff --git a/releasenotes.md b/releasenotes.md index 9f9c27ac8..940720c63 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -139,6 +139,7 @@ - Packed structs sometimes not lowered as such. - Crash when creating `$Type*` where `$Type` is an optional type #2848 - Crashes when using `io::EOF~!` in various unhandled places. #2848 +- Crash when trying to create a const zero untyped list #2847 ### 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/expr.c b/src/compiler/expr.c index 4bbe008aa..25dd829a8 100644 --- a/src/compiler/expr.c +++ b/src/compiler/expr.c @@ -702,10 +702,14 @@ void expr_rewrite_to_const_zero(Expr *expr, Type *type) case TYPE_OPTIONAL: case TYPE_TYPEINFO: case TYPE_MEMBER: - case TYPE_UNTYPED_LIST: case TYPE_INFERRED_ARRAY: case TYPE_FLEXIBLE_ARRAY: UNREACHABLE_VOID + case TYPE_UNTYPED_LIST: + expr->const_expr.const_kind = CONST_UNTYPED_LIST; + expr->const_expr.untyped_list = NULL; + expr->resolve_status = RESOLVE_DONE; + break; case TYPE_SLICE: expr_rewrite_const_empty_slice(expr, type); return; diff --git a/test/test_suite/macros/typeof_untyped_list_zero.c3t b/test/test_suite/macros/typeof_untyped_list_zero.c3t new file mode 100644 index 000000000..5e8f3c4f2 --- /dev/null +++ b/test/test_suite/macros/typeof_untyped_list_zero.c3t @@ -0,0 +1,4 @@ +fn void main() +{ + $typeof({1}) $untyped_list; +} \ No newline at end of file