mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 13:54:21 +00:00
cbe: fix bug where empty enum would be generated
fix a bug where an invalid empty enum would be emitted into the C source file if the global error set was empty.
This commit is contained in:
parent
996eb01746
commit
ce859cfcb8
1 changed files with 16 additions and 14 deletions
|
|
@ -2406,9 +2406,11 @@ pub fn genErrDecls(o: *Object) !void {
|
|||
const mod = o.dg.module;
|
||||
const writer = o.writer();
|
||||
|
||||
var max_name_len: usize = 0;
|
||||
// do not generate an invalid empty enum when the global error set is empty
|
||||
if (mod.global_error_set.keys().len > 1) {
|
||||
try writer.writeAll("enum {\n");
|
||||
o.indent_writer.pushIndent();
|
||||
var max_name_len: usize = 0;
|
||||
for (mod.global_error_set.keys()[1..], 1..) |name_nts, value| {
|
||||
const name = mod.intern_pool.stringToSlice(name_nts);
|
||||
max_name_len = @max(name.len, max_name_len);
|
||||
|
|
@ -2421,7 +2423,7 @@ pub fn genErrDecls(o: *Object) !void {
|
|||
}
|
||||
o.indent_writer.popIndent();
|
||||
try writer.writeAll("};\n");
|
||||
|
||||
}
|
||||
const array_identifier = "zig_errorName";
|
||||
const name_prefix = array_identifier ++ "_";
|
||||
const name_buf = try o.dg.gpa.alloc(u8, name_prefix.len + max_name_len);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue