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.
This commit is contained in:
Andrew Kelley 2023-07-16 23:17:45 -07:00
parent d15e8f8017
commit b03d34429d
2 changed files with 11 additions and 2 deletions

View File

@ -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;

View File

@ -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);