- Comparing a flexible array member to another type would hit an assert. #2830

- Underlying slice type not checked correctly in $defined #2829
- Checking for exhaustive cases is done even in if-chain switch if all is enum #2828
This commit is contained in:
Christoffer Lerno
2026-01-24 17:57:56 +01:00
parent 396263f5c3
commit 5e23817a3d
9 changed files with 65 additions and 1 deletions

View File

@@ -110,6 +110,9 @@
- $typeof(<type>) returns typeinfo, causing errors #2795.
- Empty ichar slice + byte concatenation hit an assert. #2789
- Remove dependency on test tmp library for stdlib compiler tests. #2800
- Comparing a flexible array member to another type would hit an assert. #2830
- Underlying slice type not checked correctly in $defined #2829
- Checking for exhaustive cases is done even in if-chain switch if all is enum #2828
### Stdlib changes
- Add `ThreadPool` join function to wait for all threads to finish in the pool without destroying the threads.

View File

@@ -10564,6 +10564,13 @@ RETRY:
Type *type = sema_expr_check_type_exists(context, type_info->array.base);
if (!type) return NULL;
if (!type_ok(type)) return type;
if (!type_is_valid_for_array(type))
{
SEMA_ERROR(type_info->array.base,
"You cannot form a slice with elements of type %s.",
type_quoted_error_string(type));
return poisoned_type;
}
return type_get_slice(type);
}
case TYPE_INFO_INFERRED_ARRAY:
@@ -10572,6 +10579,13 @@ RETRY:
Type *type = sema_expr_check_type_exists(context, type_info->array.base);
if (!type) return NULL;
if (!type_ok(type)) return type;
if (!type_is_valid_for_array(type))
{
SEMA_ERROR(type_info->array.base,
"You cannot form an array with elements of type %s.",
type_quoted_error_string(type));
return poisoned_type;
}
return type_get_inferred_array(type);
}
case TYPE_INFO_INFERRED_VECTOR:
@@ -10580,6 +10594,13 @@ RETRY:
Type *type = sema_expr_check_type_exists(context, type_info->array.base);
if (!type) return NULL;
if (!type_ok(type)) return type;
if (!type_is_valid_for_vector(type))
{
SEMA_ERROR(type_info->array.base,
"%s is not of a vectorizable type.",
type_quoted_error_string(type));
return poisoned_type;
}
return type_get_inferred_vector(type);
}
case TYPE_INFO_POINTER:

View File

@@ -2648,7 +2648,7 @@ FOUND:;
all_jump_end &= context->active_scope.end_jump.active;
SCOPE_END;
}
if (is_enum_switch && !exhaustive && success)
if (is_enum_switch && !exhaustive && success && !if_chain)
{
RETURN_SEMA_ERROR(statement, create_missing_enums_in_switch_error(cases, actual_enum_cases, enum_values));
}

View File

@@ -1066,6 +1066,10 @@ Type *type_get_optional(Type *optional_type)
Type *type_get_slice(Type *arr_type)
{
if (!type_is_valid_for_array(arr_type))
{
puts("ofek");
}
ASSERT(type_is_valid_for_array(arr_type));
return type_generate_slice(arr_type, false);
}
@@ -2273,6 +2277,7 @@ RETRY_DISTINCT:
// array + [other array, vector] => no
return NULL;
case TYPE_FLEXIBLE_ARRAY:
return NULL;
case TYPE_INFERRED_ARRAY:
case TYPE_INFERRED_VECTOR:
// Already handled

View File

@@ -0,0 +1,4 @@
fn void test1()
{
bool a = $defined(void[]); // #error: You cannot form a slice with elements of type
}

View File

@@ -0,0 +1,5 @@
fn void test2()
{
bool b = $defined(void[*]); // #error: You cannot form an array with elements of type
}

View File

@@ -0,0 +1,4 @@
fn void test1()
{
bool a = $defined(void[<*>]); // #error: 'void' is not of a vectorizable type
}

View File

@@ -0,0 +1,12 @@
enum Baz
{
A, B, C,
}
fn void test_missing_all_cases(Baz x)
{
switch (x)
{
case x:
}
}
fn int main() => 0;

View File

@@ -0,0 +1,10 @@
struct Abc
{
int x;
int[*] y;
}
fn void test()
{
Abc y;
bool same = Abc.y == y.y; // #error: 'member_ref' and 'int[*]' are different types and cannot be compared
}