#How do i make field_offset comptime known here?

1 messages · Page 1 of 1 (latest)

cedar obsidian
#
.@"struct" => |*info| {
    if (info.backing_integer) |IntType| {
        const int: IntType = @bitCast(value_pointer.*);
        return getByteAtLocalOffset(&int, offset);
    }
    var field_offset: usize = 0;
    inline for (info.fields) |*field| {
        const field_size = serializedSizeOf(field.type);
        if (field_offset + field_size > offset) {
            return getByteAtLocalOffset(&@field(value_pointer, field.name), offset - field_offset); // Error: field_offset is not comptime known but last argument of function is marked as comptime.
        }
        field_offset += field_size;
     }
     unreachable;
}
#

Since the serialized size of every field of struct field is comp-time known, so should be the serialized struct offset be.

nocturne granite
#

try:

    comptime var field_offset: usize = 0;