diff --git a/src-self-hosted/link.zig b/src-self-hosted/link.zig index 2f21dcbfde..98a2578822 100644 --- a/src-self-hosted/link.zig +++ b/src-self-hosted/link.zig @@ -86,7 +86,7 @@ pub fn writeFilePath( return result; } -pub fn openCFile(allocator: *Allocator, file: fs.File, options: Options) !File.C { +fn openCFile(allocator: *Allocator, file: fs.File, options: Options) !File.C { return File.C{ .allocator = allocator, .file = file, @@ -282,6 +282,8 @@ pub const File = struct { } } try writer.writeAll(self.main.items); + self.file.?.close(); + self.file = null; } }; diff --git a/src-self-hosted/test.zig b/src-self-hosted/test.zig index 0a32008369..3e4958cc95 100644 --- a/src-self-hosted/test.zig +++ b/src-self-hosted/test.zig @@ -480,9 +480,8 @@ pub const TestContext = struct { switch (update.case) { .Transformation => |expected_output| { if (case.cbe) { - var cfile: *link.File.C = module.bin_file.cast(link.File.C).?; - cfile.file.?.close(); - cfile.file = null; + // The C file is always closed after an update, because we don't support + // incremental updates var file = try tmp.dir.openFile(bin_name, .{ .read = true }); defer file.close(); var out = file.reader().readAllAlloc(allocator, 1024 * 1024) catch @panic("Unable to read C output!");