Update type changes.

This commit is contained in:
Christoffer Lerno
2023-08-09 01:37:14 +02:00
committed by Christoffer Lerno
parent 2ca67d1489
commit 6df6d2c084
2 changed files with 14 additions and 10 deletions

View File

@@ -537,6 +537,8 @@ static inline TypeInfo *parse_array_type_index(ParseContext *c, TypeInfo *type)
}
if (try_consume(c, TOKEN_RBRACKET))
{
bool is_resolved = type->resolve_status == RESOLVE_DONE;
if (is_resolved && !type_is_valid_for_array(type->type)) goto DIRECT_SUBARRAY;
switch (type->subtype)
{
case TYPE_COMPRESSED_NONE:
@@ -549,20 +551,20 @@ static inline TypeInfo *parse_array_type_index(ParseContext *c, TypeInfo *type)
type->subtype = TYPE_COMPRESSED_SUBSUB;
break;
default:
{
TypeInfo *subarray = type_info_new(TYPE_INFO_SUBARRAY, type->span);
subarray->array.base = type;
subarray->array.len = NULL;
RANGE_EXTEND_PREV(subarray);
return subarray;
}
goto DIRECT_SUBARRAY;
}
if (type->resolve_status == RESOLVE_DONE)
if (is_resolved)
{
type->type = type_get_subarray(type->type);
}
RANGE_EXTEND_PREV(type);
return type;
DIRECT_SUBARRAY:;
TypeInfo *subarray = type_info_new(TYPE_INFO_SUBARRAY, type->span);
subarray->array.base = type;
subarray->array.len = NULL;
RANGE_EXTEND_PREV(subarray);
return subarray;
}
TypeInfo *array = type_info_new(TYPE_INFO_ARRAY, type->span);
array->array.base = type;

View File

@@ -1108,8 +1108,8 @@ bool type_is_valid_for_array(Type *type)
switch (type->type_kind)
{
case TYPE_DISTINCT:
assert(type->decl->resolve_status == RESOLVE_DONE);
type = type->decl->define_decl.type_info->type;
assert(!type->decl || type->decl->resolve_status == RESOLVE_DONE);
type = type->decl->distinct_decl.base_type;
goto RETRY;
case TYPE_ANY:
case TYPE_ANYFAULT:
@@ -1129,6 +1129,7 @@ bool type_is_valid_for_array(Type *type)
case TYPE_VECTOR:
return true;
case TYPE_TYPEDEF:
assert(!type->decl || type->decl->resolve_status == RESOLVE_DONE);
type = type->canonical;
goto RETRY;
case TYPE_FLEXIBLE_ARRAY:
@@ -1145,6 +1146,7 @@ bool type_is_valid_for_array(Type *type)
case TYPE_VOID:
return false;
}
UNREACHABLE
}
Type *type_get_vector_bool(Type *original_type)