-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
@errorCast into an inferred error set causes compiler crash #21222
Labels
Milestone
Comments
for additional information, a program where fn func() !void {
return error.Err;
}
pub fn main() !void {
const res = func();
const err = @as(@TypeOf(res), @errorCast(error.Err));
_ = try err;
} |
debug compiler stack trace
|
Maybe known, but you can work around the current bug by stripping the error set's identity (undocumented - #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;
} |
NicoElbers
added a commit
to NicoElbers/ztest
that referenced
this issue
Sep 7, 2024
Due to a compiler bug involving inferred error sets (ziglang/zig#21222) I have to use this workaround
NicoElbers
added a commit
to NicoElbers/ztest
that referenced
this issue
Sep 11, 2024
Due to a compiler bug involving inferred error sets (ziglang/zig#21222) I have to use this workaround
NicoElbers
added a commit
to NicoElbers/ztest
that referenced
this issue
Sep 30, 2024
Due to a compiler bug involving inferred error sets (ziglang/zig#21222) I have to use this workaround
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
The text was updated successfully, but these errors were encountered: