zig
zig copied to clipboard
Compiler crashes with unreachable GenericPoison when passing struct type to fn(anytype) argument
Zig Version
0.11.0-dev.3723+423d7b848
Steps to Reproduce and Observed Output
Code:
fn hello(callback: fn (_: anytype) void) void {
_ = callback("hello world!");
}
test {
_ = hello(struct {
pub fn callback(_: anytype) void {}
});
}
Run:
zig test /Users/jarred/Desktop/repro.zig
thread 15006413 panic: zig compiler bug: GenericPoison
Unable to dump stack trace: debug info stripped
fish: Job 1, 'zig test /Users/jarred/Desktop/…' terminated by signal SIGABRT (Abort)
Expected Output
It should throw a compiler error with a stack trace pointing to the source location to make this easier to debug
Also, this code compiles but I don't think it should since callback is not a comptime argument?
fn @"hello!"(comptime Context: type, ctx: Context, callback: (fn (ctx: anytype, expr: anytype) ?*anyopaque)) void {
_ = callback(ctx, "hello world!");
}
test {
_ = @"hello!"(void, {}, struct {
pub fn callback(ctx: anytype, expr: anytype) ?*anyopaque {
_ = ctx;
_ = expr;
return null;
}
}.callback);
}