From 7813a12ed59274989ce954c931bf02ebea2a0104 Mon Sep 17 00:00:00 2001 From: Zuhaitz Méndez Fernández de Aránguiz Date: Sat, 24 Jan 2026 23:53:08 +0000 Subject: Fix for #115 --- src/codegen/codegen.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'src/codegen') diff --git a/src/codegen/codegen.c b/src/codegen/codegen.c index 038f3cb..f239bb6 100644 --- a/src/codegen/codegen.c +++ b/src/codegen/codegen.c @@ -11,7 +11,6 @@ #include "ast.h" #include "zprep_plugin.h" -// Emit literal expression (int, float, string, char) // Emit literal expression (int, float, string, char) static void codegen_literal_expr(ASTNode *node, FILE *out) { @@ -1034,6 +1033,7 @@ void codegen_expression(ParserContext *ctx, ASTNode *node, FILE *out) } int is_zen_struct = 0; + int is_union = 0; StructRef *sr = ctx->parsed_structs_list; while (sr) { @@ -1041,6 +1041,10 @@ void codegen_expression(ParserContext *ctx, ASTNode *node, FILE *out) strcmp(sr->node->strct.name, struct_name) == 0) { is_zen_struct = 1; + if (sr->node->strct.is_union) + { + is_union = 1; + } break; } sr = sr->next; @@ -1048,7 +1052,14 @@ void codegen_expression(ParserContext *ctx, ASTNode *node, FILE *out) if (is_zen_struct) { - fprintf(out, "(struct %s){", struct_name); + if (is_union) + { + fprintf(out, "(union %s){", struct_name); + } + else + { + fprintf(out, "(struct %s){", struct_name); + } } else { -- cgit v1.2.3