-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Bug: Anonymous enums can't be used with return type type
#3707
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
Comments
type
type
It seems making the fn fn foo(comptime a: enum{a,b}) void { unreachable; }
pub fn main() void {
foo(.a);
} |
This bug still persists, but i could narrow it down a bit: // making the parameter comptime enforces the error,
// making it runtime removes it.
pub fn foo(comptime a: enum{a,b}) void { unreachable; }
pub fn main() void {
foo(.a);
} Looks like the bug is somewhere in the comptime resolution of enum literals to enum type |
I believe the solution to this is going to be auditing how the comptime evaluation of parameter types are cached. This is related to #846. I want anonymous enums to also work in generic functions, after a comptime parameter. So this will require examining what "dependencies" from comptime parameters are used, and using only those as the cache key. That makes #846 a prerequisite to solving this bug. It also means that |
export fn entry() void {
repro(.a, 1);
}
fn repro(msg: enum {a, b}, comptime here_a_bug: u8) void {
switch (msg) {
.a => {},
.b => {},
}
} |
This will work with in the self-hosted compiler which is expected to ship with 0.9.0. In the meanwhile you should be able to workaround this by putting the enum in a separate declaration instead of having it as the parameter type. |
This worked earlier already but 2cfa716 added a similar enough test. |
Okay, this is a weird one. Somehow zig messes up enum literals when the type is declared local as a function parameter instead of "standalone" type. This also only happens when the return type is
type
, other types seem to work well (i32
,void
,[]const u8
):Zig Version: 0.5.0+a11da3773
The text was updated successfully, but these errors were encountered: