-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior
Description
Zig Version
0.15.2
Steps to Reproduce and Observed Behavior
See the minimum repro below:
// repro.zig
const std = @import("std");
fn rank(a: std.mem.Alignment) u3 {
return @intFromEnum(a);
}
pub fn main() void {
const a: std.mem.Alignment = .@"64";
const n = rank(a);
std.debug.print("{any} = {d}\n", .{ a, n });
}zig run repro.zig
repro.zig:4:12: error: expected type 'u3', found 'u6'
return @intFromEnum(a);
^~~~~~~~~~~~~~~
repro.zig:4:12: note: unsigned 3-bit int cannot represent all possible unsigned 6-bit values
repro.zig:3:31: note: function return type declared here
fn rank(a: std.mem.Alignment) u3 {Expected Behavior
std.mem.Alignment values ranges from 0 to 6. These fit in a u3 but std.mem.Alignment is backed by a u6 because of math.Log2Int(usize). This came up when building https://github.com/zig-gamedev/zemscripten with 0.15.2. The 3rd line of EmmallocAllocator.alloc fails with
error: expected type 'u5', found 'u6'Metadata
Metadata
Assignees
Labels
bugObserved behavior contradicts documented or intended behaviorObserved behavior contradicts documented or intended behavior