| 1 | #update=initial version |
| 2 | #file=main.zig |
| 3 | const Foo = packed struct(u8) { a: u4, b: i4 }; |
| 4 | const Bar = packed union(u10) { a: u10, b: i10 }; |
| 5 | pub fn main() void {} |
| 6 | comptime { |
| 7 | @compileLog(@typeInfo(Foo).@"struct".backing_integer.?); |
| 8 | } |
| 9 | comptime { |
| 10 | @compileLog(@bitSizeOf(Bar)); |
| 11 | } |
| 12 | const std = @import("std"); |
| 13 | const 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 |
| 21 | const Foo = packed struct(i8) { a: u4, b: i4 }; |
| 22 | const Bar = packed union(i10) { a: u10, b: i10 }; |
| 23 | pub fn main() void {} |
| 24 | comptime { |
| 25 | @compileLog(@typeInfo(Foo).@"struct".backing_integer.?); |
| 26 | } |
| 27 | comptime { |
| 28 | @compileLog(@bitSizeOf(Bar)); |
| 29 | } |
| 30 | const std = @import("std"); |
| 31 | const 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 |
| 39 | const Foo = packed struct(i5) { a: u4, b: i4 }; |
| 40 | const Bar = packed union(i8) { a: u10, b: i10 }; |
| 41 | pub fn main() void {} |
| 42 | comptime { |
| 43 | @compileLog(@typeInfo(Foo).@"struct".backing_integer.?); |
| 44 | } |
| 45 | comptime { |
| 46 | @compileLog(@bitSizeOf(Bar)); |
| 47 | } |
| 48 | const std = @import("std"); |
| 49 | const 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 |
| 60 | const Foo = packed struct(u10) { a: u4, b: i4 }; |
| 61 | const Bar = packed union(u32) { a: u10, b: i10 }; |
| 62 | pub fn main() void {} |
| 63 | comptime { |
| 64 | @compileLog(@typeInfo(Foo).@"struct".backing_integer.?); |
| 65 | } |
| 66 | comptime { |
| 67 | @compileLog(@bitSizeOf(Bar)); |
| 68 | } |
| 69 | const std = @import("std"); |
| 70 | const 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 |