From 68adadb01a2cb07fba2640afb1d52afc7dc820ee Mon Sep 17 00:00:00 2001 From: gingerBill Date: Fri, 24 Aug 2018 22:12:30 +0100 Subject: [PATCH] Allow using in structs on arrays with count <= 4 --- src/check_type.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) 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 *fields, Array const ¶ms, @@ -99,7 +112,7 @@ void check_struct_fields(CheckerContext *ctx, Ast *node, Array *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;