harec

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

commit f846805ae4ef0af3e3e317cd867618e1d023580f
parent 727a19365c777d8ac8443a4f346cc013fe61a5e3
Author: Bor Grošelj Simić <bor.groseljsimic@telemach.net>
Date:   Tue, 28 Dec 2021 22:01:10 +0100

Handle fully-qualified local identifiers consistently

Previously type aliases were treated differently than other kinds of
declarations:

// some file in namespace "ns"
let ns::var: int = 6;
type ns::typ = int;
export fn d() void =  {
	// this compiles fine
	let a: typ = 4;

	// this does not
	let b: int = var;
	return;
};

This change makes type aliases behave like the other declarations.
It also fixes a bug in type alias shadowing:

// in namespace "ns"
type a_type = int;
fn foo() void = {
	let a_type = "asdf";
	let = 5: a_type;
};

should fail to compile because local variable 'a_type' shadows the type
alias. Before this change, this did not happen in non-root namespaces
because complier first looked up 'ns::a_type' and found the type alias.

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

Diffstat:
Msrc/type_store.c | 17++---------------
1 file changed, 2 insertions(+), 15 deletions(-)

diff --git a/src/type_store.c b/src/type_store.c @@ -594,9 +594,7 @@ type_init_from_atype(struct type_store *store, // TODO: Use a dedicated error type instead of void for errors const struct scope_object *obj = NULL; - const struct identifier *ident; const struct type *builtin; - struct identifier temp; switch (type->storage) { case STORAGE_FCONST: case STORAGE_ICONST: @@ -626,22 +624,11 @@ type_init_from_atype(struct type_store *store, type->align = builtin->align; break; case STORAGE_ALIAS: - ident = &atype->alias; - if (ident->ns == NULL) { - temp = *ident; - temp.ns = store->check_context->ns; - ident = &temp; - } - - obj = scope_lookup(store->check_context->scope, ident); - if (!obj) { - obj = scope_lookup(store->check_context->scope, - &atype->alias); - } + obj = scope_lookup(store->check_context->scope, &atype->alias); if (!obj) { error(store->check_context, atype->loc, "Unresolvable identifier '%s'", - identifier_unparse(ident)); + identifier_unparse(&atype->alias)); *type = builtin_type_void; return (struct dimensions){0}; }