commit e52b8dd6d4a411f380b8dc046915991623c5b2cf
parent 41e9dd9515d5c5372382031708e73e219e913bf3
Author: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Date: Thu, 3 Mar 2022 03:38:34 +0100
prohibit embedded struct literals in named structs
The following example segfaulted instead of throwing an error:
type a = struct {
v: int,
};
let x: a = a {
v = 3,
struct {
stuff: int = 3,
},
};
Signed-off-by: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Diffstat:
1 file changed, 6 insertions(+), 0 deletions(-)
diff --git a/src/check.c b/src/check.c
@@ -2449,6 +2449,12 @@ check_expr_struct(struct context *ctx,
tnext = &tfield->next;
}
} else {
+ if (!afield->name) {
+ error(ctx, afield->initializer->loc, expr,
+ "Cannot embed a struct literal into "
+ "a named struct literal");
+ return;
+ }
sexpr->field = type_get_field(type_dealias(stype),
afield->name);
if (!sexpr->field) {