Skip to content

@tagName() fails with enum backed by signed int #16095

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

Closed
travisstaloch opened this issue Jun 19, 2023 · 2 comments · Fixed by #16096
Closed

@tagName() fails with enum backed by signed int #16095

travisstaloch opened this issue Jun 19, 2023 · 2 comments · Fixed by #16096
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. regression It worked in a previous version of Zig, but stopped working.
Milestone

Comments

@travisstaloch
Copy link
Contributor

Zig Version

0.11.0-dev.3704+729a051e9

Steps to Reproduce and Observed Behavior

it seems that using @tagName() with an i32 backed enum fails while it succeeds with a u32.

// /tmp/tmp.zig
pub const Ok = enum(u32) { a, b, c };
pub const Nok = enum(i32) { a, b, c };

test {
    _ = @tagName(Ok.a);
    _ = @tagName(Nok.a);
}
$ zig version
0.11.0-dev.3704+729a051e9

$ zig test /tmp/tmp.zig
/tmp/tmp.zig:6:9: error: no field with value '@intToEnum(tmp.Nok, 0)' in enum 'Nok'
    _ = @tagName(Nok.a);
        ^~~~~~~~~~~~~~~
/tmp/tmp.zig:2:17: note: declared here
pub const Nok = enum(i32) { a, b, c };

Expected Behavior

test should pass whether the enum is backed by a signed int or an unsigned int

@travisstaloch travisstaloch added the bug Observed behavior contradicts documented or intended behavior label Jun 19, 2023
@ifreund ifreund added this to the 0.11.0 milestone Jun 19, 2023
@ifreund ifreund added frontend Tokenization, parsing, AstGen, Sema, and Liveness. regression It worked in a previous version of Zig, but stopped working. labels Jun 19, 2023
@travisstaloch
Copy link
Contributor Author

Note: this regressed sometime in the last week or so. It was working prior to then. I discovered because of this ci failure: https://github.com/travisstaloch/protobuf-zig/actions/runs/5300787367/jobs/9594532718

@travisstaloch
Copy link
Contributor Author

travisstaloch commented Jun 19, 2023

maybe a more direct reproduction:

pub const Ok = enum(u32) { a, b, c };
pub const Nok = enum(i32) { a, b, c };

test {
    _ = @intToEnum(Ok, 0);
    _ = @intToEnum(Nok, 0);
}
$ zig test /tmp/tmp.zig
/tmp/tmp.zig:10:9: error: enum 'tmp.Nok' has no tag with value '0'
    _ = @intToEnum(Nok, 0);
        ^~~~~~~~~~~~~~~~~~
/tmp/tmp.zig:3:17: note: enum declared here
pub const Nok = enum(i32) { a, b, c };
                ^~~~~~~~~~~~~~~~~~~~~

jacobly0 added a commit to IntegratedQuantum/zig that referenced this issue Jun 20, 2023
jacobly0 added a commit to IntegratedQuantum/zig that referenced this issue Jun 20, 2023
jacobly0 added a commit to IntegratedQuantum/zig that referenced this issue Jun 20, 2023
Vexu pushed a commit that referenced this issue Jun 21, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior frontend Tokenization, parsing, AstGen, Sema, and Liveness. regression It worked in a previous version of Zig, but stopped working.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants