harec

[hare] Hare compiler, written in C11 for POSIX OSs
Log | Files | Refs | README | LICENSE

commit 251b8ac3485a3ec016a89fd8c78bec021e587f27
parent 03744ea230c5064adf9820d6390b46ecb5e1e503
Author: Bor Grošelj Simić <bgs@turminal.net>
Date:   Sat, 27 Aug 2022 13:54:33 +0200

handle unknown objects in tagged union unwrapping

Signed-off-by: Bor Grošelj Simić <bgs@turminal.net>

Diffstat:
Msrc/type_store.c | 7+++++++
Mtests/34-declarations.ha | 1+
2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/src/type_store.c b/src/type_store.c @@ -362,6 +362,13 @@ tagged_or_atagged_member(struct type_store *store, while (_atype->storage == STORAGE_ALIAS && _atype->unwrap) { const struct scope_object *obj = scope_lookup( store->check_context->scope, &_atype->alias); + if (!obj) { + error(store->check_context, _atype->loc, + "Unknown object '%s'", + identifier_unparse(&_atype->alias)); + *type = &builtin_type_void; + return; + } if (obj->otype != O_SCAN) { if (obj->otype == O_TYPE) { *type = type_dealias(obj->type); diff --git a/tests/34-declarations.ha b/tests/34-declarations.ha @@ -216,6 +216,7 @@ fn reject() void = { assert(compile("def a: int = b; def b: int = a;") as exited != EXIT_SUCCESS); assert(compile("def x: size = size(t); type t = [x]int;") as exited != EXIT_SUCCESS); assert(compile("def a: int = 12; type t = (int |(...a | a));") as exited != EXIT_SUCCESS); + assert(compile("def a: int = 12; type t = (int |(...a | a));") as exited != EXIT_SUCCESS); }; // Types t_0 to t_9 form a complete directed graph on 10 vertices.