Avoid "dependency loop detected" with function pointers

Unfortunately it is Bug #12325

Example code, from the issue, that fails to compile:

pub const DeviceCallback = *const fn (*Device) void;
pub const Device = struct {
    callback: DeviceCallback,
};

EDIT:
In the issue there is a *anyopaque workaround.

pub const DeviceCallback = *const fn (*anyopaque) void;

fn someCallback(p: *anyopaque) void {
    const device: *Device = @ptrCast(@alignCast(p));
}
2 Likes