|
@@ -144,6 +144,7 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Slice<Entity *> *fields
|
|
}
|
|
}
|
|
|
|
|
|
bool is_using = (p->flags&FieldFlag_using) != 0;
|
|
bool is_using = (p->flags&FieldFlag_using) != 0;
|
|
|
|
+ bool is_subtype = (p->flags&FieldFlag_subtype) != 0;
|
|
|
|
|
|
for_array(j, p->names) {
|
|
for_array(j, p->names) {
|
|
Ast *name = p->names[j];
|
|
Ast *name = p->names[j];
|
|
@@ -158,6 +159,9 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Slice<Entity *> *fields
|
|
Entity *field = alloc_entity_field(ctx->scope, name_token, type, is_using, field_src_index);
|
|
Entity *field = alloc_entity_field(ctx->scope, name_token, type, is_using, field_src_index);
|
|
add_entity(ctx, ctx->scope, name, field);
|
|
add_entity(ctx, ctx->scope, name, field);
|
|
field->Variable.field_group_index = field_group_index;
|
|
field->Variable.field_group_index = field_group_index;
|
|
|
|
+ if (is_subtype) {
|
|
|
|
+ field->flags |= EntityFlag_Subtype;
|
|
|
|
+ }
|
|
|
|
|
|
if (j == 0) {
|
|
if (j == 0) {
|
|
field->Variable.docs = docs;
|
|
field->Variable.docs = docs;
|
|
@@ -194,6 +198,20 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Slice<Entity *> *fields
|
|
|
|
|
|
populate_using_entity_scope(ctx, node, p, type);
|
|
populate_using_entity_scope(ctx, node, p, type);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ if (is_subtype && p->names.count > 0) {
|
|
|
|
+ Type *first_type = fields_array[fields_array.count-1]->type;
|
|
|
|
+ Type *t = base_type(type_deref(first_type));
|
|
|
|
+
|
|
|
|
+ if (!does_field_type_allow_using(t) &&
|
|
|
|
+ p->names.count >= 1 &&
|
|
|
|
+ p->names[0]->kind == Ast_Ident) {
|
|
|
|
+ Token name_token = p->names[0]->Ident.token;
|
|
|
|
+ gbString type_str = type_to_string(first_type);
|
|
|
|
+ error(name_token, "'subtype' cannot be applied to the field '%.*s' of type '%s'", LIT(name_token.string), type_str);
|
|
|
|
+ gb_string_free(type_str);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
*fields = slice_from_array(fields_array);
|
|
*fields = slice_from_array(fields_array);
|