Commit 701cebeb30

Andrew Kelley <andrew@ziglang.org>
2022-12-04 03:41:35
CBE: fix union init wrong field name
1 parent aa98517
Changed files (1)
src
codegen
src/codegen/c.zig
@@ -6436,10 +6436,15 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue {
             try f.writeCValue(writer, local, .Other);
             try writer.print(".tag = {}; ", .{try f.fmtIntLiteral(tag_ty, int_val)});
         }
+        try f.writeCValue(writer, local, .Other);
+        try writer.print(".payload.{ } = ", .{fmtIdent(field_name)});
+        try f.writeCValue(writer, payload, .Other);
+        try writer.writeAll(";\n");
+        return local;
     }
 
     try f.writeCValue(writer, local, .Other);
-    try writer.print(".payload.{ } = ", .{fmtIdent(field_name)});
+    try writer.print(".{ } = ", .{fmtIdent(field_name)});
     try f.writeCValue(writer, payload, .Other);
     try writer.writeAll(";\n");