From 4ae3d0150f2d6c05be6f425eaab32fcd945f5516 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Sun, 15 Dec 2024 20:42:42 +0100 Subject: [PATCH] Fix case trying to initialize a `char[*]*` from a String. --- releasenotes.md | 11 +++++++++++ src/compiler/sema_casts.c | 6 ++++-- test/test_suite/cast/cast_string_to_infered_array.c3 | 6 ++++++ 3 files changed, 21 insertions(+), 2 deletions(-) create mode 100644 test/test_suite/cast/cast_string_to_infered_array.c3 diff --git a/releasenotes.md b/releasenotes.md index cf7bba4a4..e0034e9f3 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -1,5 +1,16 @@ # C3C Release Notes +## 0.6.6 Change list + +### Changes / improvements +None + +### Fixes +- Fix case trying to initialize a `char[*]*` from a String. + +### Stdlib changes +None + ## 0.6.5 Change list ### Changes / improvements diff --git a/src/compiler/sema_casts.c b/src/compiler/sema_casts.c index fc65d0cf9..4ed303eb8 100644 --- a/src/compiler/sema_casts.c +++ b/src/compiler/sema_casts.c @@ -239,13 +239,15 @@ Type *type_infer_len_from_actual_type(Type *to_infer, Type *actual_type) // And from the actual type. actual_type = type_no_optional(actual_type); + Type *actual = type_get_indexed_type(actual_type); + if (!actual) return actual_type; + // Grab the underlying indexed type, // because we can only have [*] [] [<*>] [<>] * here Type *indexed = type_get_indexed_type(to_infer); - Type *actual = type_get_indexed_type(actual_type); // We should always have indexed types. - ASSERT0(indexed && actual); + ASSERT0(indexed); // The underlying type may also be inferred. // In this case, infer it. diff --git a/test/test_suite/cast/cast_string_to_infered_array.c3 b/test/test_suite/cast/cast_string_to_infered_array.c3 new file mode 100644 index 000000000..0e5824fff --- /dev/null +++ b/test/test_suite/cast/cast_string_to_infered_array.c3 @@ -0,0 +1,6 @@ +import std; +fn void main() +{ + char[*]* x = "abc"; // #error: You cannot cast 'String' to 'char[*]*' + io::printn($typeof(x).nameof); +} \ No newline at end of file