From b03d34429d059dc3f6056d7f780dc623c96523b4 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Sun, 16 Jul 2023 23:17:45 -0700 Subject: [PATCH] compiler: work around slightly different generics semantics Both of these cases are interesting, were not covered by behavior tests, and should be inspected carefully with regards to the language specification. --- src/Zir.zig | 6 +++++- src/codegen/c.zig | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/Zir.zig b/src/Zir.zig index 56355fd72a..572471c863 100644 --- a/src/Zir.zig +++ b/src/Zir.zig @@ -65,9 +65,13 @@ pub const ExtraIndex = enum(u32) { _, }; +fn ExtraData(comptime T: type) type { + return struct { data: T, end: usize }; +} + /// Returns the requested data, as well as the new index which is at the start of the /// trailers for the object. -pub fn extraData(code: Zir, comptime T: type, index: usize) struct { data: T, end: usize } { +pub fn extraData(code: Zir, comptime T: type, index: usize) ExtraData(T) { const fields = @typeInfo(T).Struct.fields; var i: usize = index; var result: T = undefined; diff --git a/src/codegen/c.zig b/src/codegen/c.zig index 6533173805..1ab5a976cd 100644 --- a/src/codegen/c.zig +++ b/src/codegen/c.zig @@ -1802,7 +1802,12 @@ pub const DeclGen = struct { } } - fn writeCValueMember(dg: *DeclGen, writer: anytype, c_value: CValue, member: CValue) !void { + fn writeCValueMember( + dg: *DeclGen, + writer: anytype, + c_value: CValue, + member: CValue, + ) error{ OutOfMemory, AnalysisFail }!void { try dg.writeCValue(writer, c_value); try writer.writeByte('.'); try dg.writeCValue(writer, member);