harec

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

commit cd4b6de8024b23b459ae07ac43f6cd588c22ee48
parent 71a624b4b4071d591c532df1dcd422c1a6ad599c
Author: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Date:   Mon, 26 Apr 2021 14:59:17 +0200

print an error message for duplicate struct/union members

Signed-off-by: Bor Grošelj Simić <bor.groseljsimic@telemach.net>

Diffstat:
Msrc/type_store.c | 4+++-
Mtests/06-structs.ha | 2++
2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/type_store.c b/src/type_store.c @@ -171,7 +171,9 @@ struct_insert_field(struct type_store *store, struct struct_field **fields, struct struct_field *field, _temp = {0}; if (fields != NULL) { field = *fields; - assert(field == NULL || strcmp(field->name, atype->field.name) != 0); + expect(&atype->field.type->loc, + field == NULL || strcmp(field->name, atype->field.name) != 0, + "Duplicate struct/union member '%s'", atype->field.name); *fields = xcalloc(1, sizeof(struct struct_field)); (*fields)->next = field; field = *fields; diff --git a/tests/06-structs.ha b/tests/06-structs.ha @@ -100,6 +100,8 @@ fn invariants() void = { }; ", + // Duplicate members + "fn test() void = { let x: struct { a: int, a: int } = struct { a: int = 2 };" // Dereference non-nullable pointer: "fn test() void = { let x: nullable *struct { y: int } = null; x.y; };", // Select field from non-struct object: