Open NicoElbers opened 2 months ago
for additional information, a program where error.Err
should be in the inferred error set also crashes:
fn func() !void {
return error.Err;
}
pub fn main() !void {
const res = func();
const err = @as(@TypeOf(res), @errorCast(error.Err));
_ = try err;
}
Maybe known, but you can work around the current bug by stripping the error set's identity (undocumented - https://github.com/ziglang/zig/issues/20862):
fn func() !void {
return;
}
fn StripErrorSetIdentity(T: type) type {
return switch (@typeInfo(T)) {
else => |tag| @compileError("invalid input type: " ++ @typeName(T) ++ " | " ++ @tagName(tag)),
.ErrorSet => T || error{},
.ErrorUnion => |u| StripErrorSetIdentity(u.error_set)!u.payload,
};
}
pub fn main() !void {
const res = func();
const Res = StripErrorSetIdentity(@TypeOf(res));
const err = @as(Res, @errorCast(error.Err));
_ = try err;
}
Zig Version
0.14.0-dev.1307+849c31a6c
Steps to Reproduce and Observed Behavior
bug.zig
:run
zig build-exe bug.zig
observe:
full dump of a debug compiler here: https://pastebin.com/9bncrwdm
Expected Behavior
A compiling program, as what would happen if func returned
anyerror!void