harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 7cc7111d4d7717bbdd42ca65b5e0bb3c1d5fdf26
parent cd83be45847f4a17c15ae88a9edc068e2d7a63bc
Author: Alexey Yerin <yyp@disroot.org>
Date:   Wed, 27 Apr 2022 23:03:09 +0300

type_store: add location to non-struct/union embedding error

Fixes: https://todo.sr.ht/~sircmpwn/hare/635
Signed-off-by: Alexey Yerin <yyp@disroot.org>

Diffstat:
Msrc/type_store.c | 16++++++----------
1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/type_store.c b/src/type_store.c @@ -220,18 +220,14 @@ struct_insert_field(struct type_store *store, struct struct_field **fields, static const struct type *type_store_lookup_type(struct type_store *store, const struct type *type); void -shift_fields(struct type_store *store, struct struct_field *parent) +shift_fields(struct type_store *store, + const struct ast_struct_union_type *atype, struct struct_field *parent) { if (parent->type->storage == STORAGE_ALIAS && type_dealias(parent->type)->storage != STORAGE_STRUCT && type_dealias(parent->type)->storage != STORAGE_UNION) { - // TODO - struct location loc = { - .path = "<unknown>", - .lineno = 0, - .colno = 0, - }; - error(store->check_context, loc, + assert(atype); + error(store->check_context, atype->type->loc, "Cannot embed non-struct non-union alias"); return; } @@ -263,7 +259,7 @@ shift_fields(struct type_store *store, struct struct_field *parent) if (field->name) { new->name = strdup(field->name); } else { - shift_fields(store, new); + shift_fields(store, NULL, new); } // Sub-subfields are shifted by field->offset in the recursive // shift_fields call, delay adding it to new->offset to avoid @@ -295,7 +291,7 @@ struct_init_from_atype(struct type_store *store, enum type_storage storage, // type_get_field far easier to implement and doesn't // cause any trouble in gen since offsets are only used // there for sorting fields. - shift_fields(store, field); + shift_fields(store, atype, field); } atype = atype->next; }