commit 9062c3682fb11aa1b11050eb91da9bcf38299986
parent e7dce90c1bcded8c6df2945eb5820e77632a172f
Author: Ember Sawady <ecs@d2evs.net>
Date: Mon, 6 Feb 2023 16:34:22 +0000
Don't crash on use of structs with invalid embeds
Signed-off-by: Ember Sawady <ecs@d2evs.net>
Diffstat:
3 files changed, 9 insertions(+), 0 deletions(-)
diff --git a/src/type_store.c b/src/type_store.c
@@ -243,6 +243,7 @@ shift_fields(struct type_store *store,
assert(afield);
error(store->check_context, afield->type->loc,
"Cannot embed non-struct non-union alias");
+ parent->type = &builtin_type_error;
return;
}
if (parent->offset == 0) {
diff --git a/src/types.c b/src/types.c
@@ -58,6 +58,9 @@ type_get_field(const struct type *type, const char *name)
{
// TODO: We should consider lowering unions into structs with explicit
// offsets
+ if (type->storage == STORAGE_ERROR) {
+ return NULL;
+ };
assert(type->storage == STORAGE_STRUCT
|| type->storage == STORAGE_UNION);
struct struct_field *field = type->struct_union.fields;
diff --git a/tests/26-regression.ha b/tests/26-regression.ha
@@ -94,4 +94,9 @@ export fn main() void = {
assert(rt::compile("def A: a = 1 % 1;") as rt::exited != rt::EXIT_SUCCESS);
assert(rt::compile("def A: b = void;") as rt::exited != rt::EXIT_SUCCESS);
static assert(true == true && true != false);
+ assert(rt::compile("
+ type a = str;
+ type b = struct { a };
+ def A = b { c = 0 };"
+ ) as rt::exited != rt::EXIT_SUCCESS);
};