A distinct type based on an array would yield .len == 0

This commit is contained in:
Christoffer Lerno
2025-07-18 21:24:09 +02:00
parent 2acf3c57c7
commit e9aee55714
3 changed files with 15 additions and 4 deletions

View File

@@ -62,6 +62,7 @@
- Fix unexpected display of macro definition when passing a poisoned expression #2305.
- `@links` on macros would not be added to calling functions.
- Fix `Formatter.print` returning incorrect size.
- A distinct type based on an array would yield .len == 0
### Stdlib changes
- Improve contract for readline. #2280

View File

@@ -4862,16 +4862,20 @@ static inline bool sema_create_const_len(Expr *expr, Type *type, Type *flat)
ASSERT_SPAN(expr, flat == type_flatten(flat) && "Should be flattened already.");
size_t len;
if (type->type_kind == TYPE_CONST_ENUM) goto ENUMS;
if (type->type_kind == TYPE_CONST_ENUM)
{
len = vec_size(type->decl->enums.values);
expr_rewrite_const_int(expr, type_usz, len);
return true;
}
switch (flat->type_kind)
{
case TYPE_ARRAY:
case TYPE_VECTOR:
len = type->array.len;
len = flat->array.len;
break;
case TYPE_ENUM:
ENUMS:
len = vec_size(type->decl->enums.values);
len = vec_size(flat->decl->enums.values);
break;
case TYPE_INFERRED_ARRAY:
case TYPE_FLEXIBLE_ARRAY:

View File

@@ -0,0 +1,6 @@
typedef Foo = int[32];
fn int main()
{
$assert(Foo.len == 32);
return 0;
}