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