aboutsummaryrefslogtreecommitdiff
path: root/src/check_type.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-02-16 11:54:15 +0000
committergingerBill <bill@gingerbill.org>2022-02-16 11:54:15 +0000
commit65dedbb1caaa785a444d32a7a15adaf6c396b07f (patch)
tree37e749a36d79ad05c5e4097b319ae218ba87caac /src/check_type.cpp
parent0e69993d39e367a67911f361fde0ad2b58f6d4ea (diff)
Add `#subtype` struct field prefix, required to have a COM interface hierarchy
Diffstat (limited to 'src/check_type.cpp')
-rw-r--r--src/check_type.cpp18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp
index 32340070e..7e0ad2bd9 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -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_subtype = (p->flags&FieldFlag_subtype) != 0;
for_array(j, p->names) {
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);
add_entity(ctx, ctx->scope, name, field);
field->Variable.field_group_index = field_group_index;
+ if (is_subtype) {
+ field->flags |= EntityFlag_Subtype;
+ }
if (j == 0) {
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);
}
+
+ 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);