commit 7f428e7c869bef3d52d12ccdaf8d7002d4fae9e9
parent d1e9fcea7c5b85e57dbf0a9b77cc4bd693865b1b
Author: Drew DeVault <sir@cmpwn.com>
Date: Sat, 29 Jan 2022 09:55:53 +0100
Allow @init/@fini funcs to share name
Much like @test.
Signed-off-by: Drew DeVault <sir@cmpwn.com>
Diffstat:
3 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/src/check.c b/src/check.c
@@ -3307,7 +3307,7 @@ scan_function(struct context *ctx, const struct ast_function_decl *decl)
const struct type *fntype = type_store_lookup_atype(
ctx->store, &fn_atype);
- if (!(decl->flags & FN_TEST)) {
+ if (!decl->flags) {
struct identifier ident = {0};
if (decl->symbol) {
ident.name = strdup(decl->symbol);
@@ -3496,10 +3496,8 @@ scan_decl_start(struct context *ctx, struct scope *imports, struct ast_decl *dec
}
break;
case AST_DECL_FUNC:
- if ((decl->function.flags & FN_TEST)) {
- if (ctx->is_test) {
- scan_function(ctx, &decl->function);
- }
+ if (decl->function.flags) {
+ scan_function(ctx, &decl->function);
return;
}
struct ast_function_decl *func = &decl->function;
diff --git a/src/gen.c b/src/gen.c
@@ -2902,6 +2902,10 @@ gen_function_decl(struct gen_context *ctx, const struct declaration *decl)
if (func->flags & FN_TEST) {
qdef->name = gen_name(ctx, "testfunc.%d");
+ } else if (func->flags & FN_INIT) {
+ qdef->name = gen_name(ctx, "initfunc.%d");
+ } else if (func->flags & FN_FINI) {
+ qdef->name = gen_name(ctx, "finifunc.%d");
} else {
qdef->name = decl->symbol ? strdup(decl->symbol)
: ident_to_sym(&decl->ident);
diff --git a/tests/09-funcs.ha b/tests/09-funcs.ha
@@ -38,10 +38,18 @@ let x: int = 42;
x = 1337;
};
+@init fn init() void = {
+ void; // Should be allowed to have the same name
+};
+
@fini fn fini() void = {
rt::exit(42); // Magic number
};
+@fini fn fini() void = {
+ void; // Should be allowed to have the same name
+};
+
export fn main() void = {
assert(simple() == 69);
pointers();