authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-16 23:17:45-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-07-18 19:02:06-07:00
logb03d34429d059dc3f6056d7f780dc623c96523b4
tree481abfc5bf9ba31e2e9934c4c2616861010df40b
parentd15e8f8017758fb77dd6e839ef3f39b174522c5c

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.

2 files changed, 11 insertions(+), 2 deletions(-)

src/Zir.zig+5-1
...@@ -65,9 +65,13 @@ pub const ExtraIndex = enum(u32) {...@@ -65,9 +65,13 @@ pub const ExtraIndex = enum(u32) {
65 _,65 _,
66};66};
6767
68fn ExtraData(comptime T: type) type {
69 return struct { data: T, end: usize };
70}
71
68/// Returns the requested data, as well as the new index which is at the start of the72/// Returns the requested data, as well as the new index which is at the start of the
69/// trailers for the object.73/// trailers for the object.
70pub fn extraData(code: Zir, comptime T: type, index: usize) struct { data: T, end: usize } {74pub fn extraData(code: Zir, comptime T: type, index: usize) ExtraData(T) {
71 const fields = @typeInfo(T).Struct.fields;75 const fields = @typeInfo(T).Struct.fields;
72 var i: usize = index;76 var i: usize = index;
73 var result: T = undefined;77 var result: T = undefined;
src/codegen/c.zig+6-1
...@@ -1802,7 +1802,12 @@ pub const DeclGen = struct {...@@ -1802,7 +1802,12 @@ pub const DeclGen = struct {
1802 }1802 }
1803 }1803 }
18041804
1805 fn writeCValueMember(dg: *DeclGen, writer: anytype, c_value: CValue, member: CValue) !void {1805 fn writeCValueMember(
1806 dg: *DeclGen,
1807 writer: anytype,
1808 c_value: CValue,
1809 member: CValue,
1810 ) error{ OutOfMemory, AnalysisFail }!void {
1806 try dg.writeCValue(writer, c_value);1811 try dg.writeCValue(writer, c_value);
1807 try writer.writeByte('.');1812 try writer.writeByte('.');
1808 try dg.writeCValue(writer, member);1813 try dg.writeCValue(writer, member);