commit 25842ee8d72f63351c51be65ce457a568c2be59d
parent fc7c103e72f5358142ed8a0492f06a74447fcdcf
Author: Ember Sawady <ecs@d2evs.net>
Date: Wed, 1 Feb 2023 20:14:10 +0000
Fix exported globals with inferred types
Signed-off-by: Ember Sawady <ecs@d2evs.net>
Diffstat:
2 files changed, 12 insertions(+), 3 deletions(-)
diff --git a/src/typedef.c b/src/typedef.c
@@ -367,7 +367,11 @@ emit_decl_const(struct declaration *decl, FILE *out)
{
char *ident = identifier_unparse(&decl->ident);
fprintf(out, "export def %s: ", ident);
- emit_exported_type(decl->constant.type, out, ident);
+ if (decl->constant.type) {
+ emit_exported_type(decl->constant.type, out, ident);
+ } else {
+ emit_exported_type(decl->constant.value->result, out, ident);
+ };
free(ident);
fprintf(out, " = ");
emit_const(decl->constant.value, out);
@@ -422,7 +426,11 @@ emit_decl_global(struct declaration *decl, FILE *out)
fprintf(out, "@threadlocal ");
}
fprintf(out, "%s: ", ident);
- emit_exported_type(decl->global.type, out, ident);
+ if (decl->constant.type) {
+ emit_exported_type(decl->global.type, out, ident);
+ } else {
+ emit_exported_type(decl->global.value->result, out, ident);
+ };
fprintf(out, ";\n");
free(ident);
}
diff --git a/testmod/testmod.ha b/testmod/testmod.ha
@@ -16,6 +16,7 @@ export type char_enum = enum char {
export type enum_alias = _enum;
export type error_enum = !_enum;
-export def val: int = 42;
+export def val = 42;
export def val2: int = 90;
export def val3: enum_alias = 1: enum_alias;
+export let val4 = 69;