commit decd52cf53c7dae2dbd0db9eb52f61394c028ced
parent 20e22ea531241c6633a947dd1d42818778259f5c
Author: Armin Weigl <tb46305@gmail.com>
Date: Sat, 2 Jul 2022 10:26:12 +0200
emit_const: correctly emit enum aliases
Signed-off-by: Armin Weigl <tb46305@gmail.com>
Diffstat:
2 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/typedef.c b/src/typedef.c
@@ -121,10 +121,9 @@ emit_const(const struct expression *expr, FILE *out)
};
fprintf(out, "\"");
break;
- case STORAGE_ENUM:
- assert(expr->result->storage == STORAGE_ENUM);
+ case STORAGE_ENUM: {
const struct type *t = type_dealias(expr->result);
- char *ident = identifier_unparse(&t->alias.ident);
+ char *ident = identifier_unparse(&expr->result->alias.ident);
if (t->alias.type->storage == STORAGE_CHAR) {
fprintf(out, "%" PRIuMAX, val->uval);
} else if (t->alias.type->storage == STORAGE_UINTPTR) {
@@ -138,6 +137,7 @@ emit_const(const struct expression *expr, FILE *out)
}
free(ident);
break;
+ }
case STORAGE_ALIAS:
case STORAGE_ARRAY:
case STORAGE_SLICE:
diff --git a/testmod/testmod.ha b/testmod/testmod.ha
@@ -17,3 +17,4 @@ export type enum_alias = _enum;
export def val: int = 42;
export def val2: int = 90;
+export def val3: enum_alias = 1: enum_alias;