diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2022-02-17 23:15:38 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-17 23:15:38 +0000 |
| commit | 8f13724a4b9782d7ac8e6a8037d0a44cfd41e240 (patch) | |
| tree | aed1e727a6c53cc6704f927fe118f740bbdf4a29 /src/check_type.cpp | |
| parent | 89b7a3f7ac1388ea9e8752f9445843aa58b157be (diff) | |
| parent | 746d5fc322a410625435fd05bb847481919a918f (diff) | |
Merge pull request #1504 from odin-lang/directx-packages
DirectX Package Support
Diffstat (limited to 'src/check_type.cpp')
| -rw-r--r-- | src/check_type.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp index 976bb7f42..64fb67723 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); |