mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
A distinct type based on an array would yield .len == 0
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
typedef Foo = int[32];
|
||||
fn int main()
|
||||
{
|
||||
$assert(Foo.len == 32);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user