Skip to content
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

`@intCast` should work for `comptime_int` sometimes #1712

Closed
thejoshwolfe opened this Issue Nov 9, 2018 · 0 comments

Comments

Projects
None yet
2 participants
@thejoshwolfe
Copy link
Member

commented Nov 9, 2018

const std = @import("std");

test "asdf" {
    std.debug.assert(@intCast(comptime_int, 0) == 0);
}
$ zig test asdf.zig 
asdf.zig:4:31: error: expected integer type, found 'comptime_int'
    std.debug.assert(@intCast(comptime_int, 0) == 0);
                              ^

This came up when I was trying to switch on an integer that represented a union(enum) tag value. Consider this example:

const std = @import("std");

const Foo = union(enum).{
    A,
};

test "asdf" {
    const tag_int = 0;
    const tag = @intToEnum(@TagType(Foo), @intCast(@TagType(@TagType(Foo)), tag_int));
}
$ zig test asdf.zig 
asdf.zig:9:52: error: expected integer type, found 'comptime_int'
    const tag = @intToEnum(@TagType(Foo), @intCast(@TagType(@TagType(Foo)), tag_int));
                                                   ^

But if you add another item B, to Foo, then it compiles fine, because then the tag value is no longer a comptime_int.

@andrewrk andrewrk added this to the 0.4.0 milestone Nov 9, 2018

@andrewrk andrewrk added the bug label Nov 18, 2018

@andrewrk andrewrk closed this in f8a782f Nov 19, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.