aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2018-08-24 22:12:30 +0100
committergingerBill <bill@gingerbill.org>2018-08-24 22:12:30 +0100
commit68adadb01a2cb07fba2640afb1d52afc7dc820ee (patch)
tree000109aa7109a00f0d61a7d29c55f2b61e85388f
parentd56f458d1168d08522584e9b426aae0c3bb18b49 (diff)
Allow using in structs on arrays with count <= 4
-rw-r--r--src/check_type.cpp15
1 files changed, 14 insertions, 1 deletions
diff --git a/src/check_type.cpp b/src/check_type.cpp
index a285bc413..b6d99772e 100644
--- a/src/check_type.cpp
+++ b/src/check_type.cpp
@@ -28,7 +28,20 @@ void populate_using_entity_scope(CheckerContext *ctx, Ast *node, Type *t) {
}
}
}
+}
+bool does_field_type_allow_using(Type *t) {
+ t = base_type(t);
+ if (is_type_struct(t)) {
+ return true;
+ } else if (is_type_raw_union(t)) {
+ return true;
+ } else if (is_type_bit_field(t)) {
+ return true;
+ } else if (is_type_array(t)) {
+ return t->Array.count <= 4;
+ }
+ return false;
}
void check_struct_fields(CheckerContext *ctx, Ast *node, Array<Entity *> *fields, Array<Ast *> const &params,
@@ -99,7 +112,7 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Array<Entity *> *fields
Type *first_type = (*fields)[fields->count-1]->type;
Type *t = base_type(type_deref(first_type));
- if (!is_type_struct(t) && !is_type_raw_union(t) && !is_type_bit_field(t) &&
+ 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;