1#update=initial version
2#file=main.zig
3const Foo = packed struct(u8) { a: u4, b: i4 };
4const Bar = packed union(u10) { a: u10, b: i10 };
5pub fn main() void {}
6comptime {
7 @compileLog(@typeInfo(Foo).@"struct".backing_integer.?);
8}
9comptime {
10 @compileLog(@bitSizeOf(Bar));
11}
12const std = @import("std");
13const io = std.Io.Threaded.global_single_threaded.io();
14#expect_error=main.zig:5:5: error: found compile log statement
15#expect_error=main.zig:8:5: note: also here
16#expect_compile_log=@as(type, u8)
17#expect_compile_log=@as(comptime_int, 10)
18
19#update=make backing types signed
20#file=main.zig
21const Foo = packed struct(i8) { a: u4, b: i4 };
22const Bar = packed union(i10) { a: u10, b: i10 };
23pub fn main() void {}
24comptime {
25 @compileLog(@typeInfo(Foo).@"struct".backing_integer.?);
26}
27comptime {
28 @compileLog(@bitSizeOf(Bar));
29}
30const std = @import("std");
31const io = std.Io.Threaded.global_single_threaded.io();
32#expect_error=main.zig:5:5: error: found compile log statement
33#expect_error=main.zig:8:5: note: also here
34#expect_compile_log=@as(type, i8)
35#expect_compile_log=@as(comptime_int, 10)
36
37#update=make backing types too small
38#file=main.zig
39const Foo = packed struct(i5) { a: u4, b: i4 };
40const Bar = packed union(i8) { a: u10, b: i10 };
41pub fn main() void {}
42comptime {
43 @compileLog(@typeInfo(Foo).@"struct".backing_integer.?);
44}
45comptime {
46 @compileLog(@bitSizeOf(Bar));
47}
48const std = @import("std");
49const io = std.Io.Threaded.global_single_threaded.io();
50#expect_error=main.zig:1:20: error: backing integer bit width does not match total bit width of fields
51#expect_error=main.zig:1:27: note: backing integer 'i5' has bit width '5'
52#expect_error=main.zig:1:20: note: struct fields have total bit width '8'
53#expect_error=main.zig:2:35: error: field bit width does not match backing integer
54#expect_error=main.zig:2:35: note: field type 'u10' has bit width '10'
55#expect_error=main.zig:2:26: note: backing integer 'i8' has bit width '8'
56#expect_error=main.zig:2:35: note: all fields in a packed union must have the same bit width
57
58#update=make backing types too big
59#file=main.zig
60const Foo = packed struct(u10) { a: u4, b: i4 };
61const Bar = packed union(u32) { a: u10, b: i10 };
62pub fn main() void {}
63comptime {
64 @compileLog(@typeInfo(Foo).@"struct".backing_integer.?);
65}
66comptime {
67 @compileLog(@bitSizeOf(Bar));
68}
69const std = @import("std");
70const io = std.Io.Threaded.global_single_threaded.io();
71#expect_error=main.zig:1:20: error: backing integer bit width does not match total bit width of fields
72#expect_error=main.zig:1:27: note: backing integer 'u10' has bit width '10'
73#expect_error=main.zig:1:20: note: struct fields have total bit width '8'
74#expect_error=main.zig:2:36: error: field bit width does not match backing integer
75#expect_error=main.zig:2:36: note: field type 'u10' has bit width '10'
76#expect_error=main.zig:2:26: note: backing integer 'u32' has bit width '32'
77#expect_error=main.zig:2:36: note: all fields in a packed union must have the same bit width