incremental: add misssing dependency on backing/tag type source code

This commit is contained in:
Matthew Lugg
2026-04-22 13:08:52 +01:00
committed by Andrew Kelley
parent 9c7759bdc3
commit 99b90a4315
4 changed files with 163 additions and 12 deletions
@@ -0,0 +1,77 @@
#update=initial version
#file=main.zig
const Foo = packed struct(u8) { a: u4, b: i4 };
const Bar = packed union(u10) { a: u10, b: i10 };
pub fn main() void {}
comptime {
@compileLog(@typeInfo(Foo).@"struct".backing_integer.?);
}
comptime {
@compileLog(@bitSizeOf(Bar));
}
const std = @import("std");
const io = std.Io.Threaded.global_single_threaded.io();
#expect_error=main.zig:5:5: error: found compile log statement
#expect_error=main.zig:8:5: note: also here
#expect_compile_log=@as(type, u8)
#expect_compile_log=@as(comptime_int, 10)
#update=make backing types signed
#file=main.zig
const Foo = packed struct(i8) { a: u4, b: i4 };
const Bar = packed union(i10) { a: u10, b: i10 };
pub fn main() void {}
comptime {
@compileLog(@typeInfo(Foo).@"struct".backing_integer.?);
}
comptime {
@compileLog(@bitSizeOf(Bar));
}
const std = @import("std");
const io = std.Io.Threaded.global_single_threaded.io();
#expect_error=main.zig:5:5: error: found compile log statement
#expect_error=main.zig:8:5: note: also here
#expect_compile_log=@as(type, i8)
#expect_compile_log=@as(comptime_int, 10)
#update=make backing types too small
#file=main.zig
const Foo = packed struct(i5) { a: u4, b: i4 };
const Bar = packed union(i8) { a: u10, b: i10 };
pub fn main() void {}
comptime {
@compileLog(@typeInfo(Foo).@"struct".backing_integer.?);
}
comptime {
@compileLog(@bitSizeOf(Bar));
}
const std = @import("std");
const io = std.Io.Threaded.global_single_threaded.io();
#expect_error=main.zig:1:20: error: backing integer bit width does not match total bit width of fields
#expect_error=main.zig:1:27: note: backing integer 'i5' has bit width '5'
#expect_error=main.zig:1:20: note: struct fields have total bit width '8'
#expect_error=main.zig:2:35: error: field bit width does not match backing integer
#expect_error=main.zig:2:35: note: field type 'u10' has bit width '10'
#expect_error=main.zig:2:26: note: backing integer 'i8' has bit width '8'
#expect_error=main.zig:2:35: note: all fields in a packed union must have the same bit width
#update=make backing types too big
#file=main.zig
const Foo = packed struct(u10) { a: u4, b: i4 };
const Bar = packed union(u32) { a: u10, b: i10 };
pub fn main() void {}
comptime {
@compileLog(@typeInfo(Foo).@"struct".backing_integer.?);
}
comptime {
@compileLog(@bitSizeOf(Bar));
}
const std = @import("std");
const io = std.Io.Threaded.global_single_threaded.io();
#expect_error=main.zig:1:20: error: backing integer bit width does not match total bit width of fields
#expect_error=main.zig:1:27: note: backing integer 'u10' has bit width '10'
#expect_error=main.zig:1:20: note: struct fields have total bit width '8'
#expect_error=main.zig:2:36: error: field bit width does not match backing integer
#expect_error=main.zig:2:36: note: field type 'u10' has bit width '10'
#expect_error=main.zig:2:26: note: backing integer 'u32' has bit width '32'
#expect_error=main.zig:2:36: note: all fields in a packed union must have the same bit width
+32
View File
@@ -59,3 +59,35 @@ pub fn main() !void {
const std = @import("std");
const io = std.Io.Threaded.global_single_threaded.io();
#expect_stdout="a\n"
#update=specify tag directly
#file=main.zig
const Foo = enum(u3) {
a,
b,
c,
d,
e,
};
pub fn main() !void {
@compileLog(@typeInfo(Foo).@"enum".tag_type);
}
const std = @import("std");
const io = std.Io.Threaded.global_single_threaded.io();
#expect_error=main.zig:9:5: error: found compile log statement
#expect_compile_log=@as(type, u3)
#update=change directly-specified tag type
#file=main.zig
const Foo = enum(u8) {
a,
b,
c,
d,
e,
};
pub fn main() !void {
@compileLog(@typeInfo(Foo).@"enum".tag_type);
}
const std = @import("std");
const io = std.Io.Threaded.global_single_threaded.io();
#expect_error=main.zig:9:5: error: found compile log statement
#expect_compile_log=@as(type, u8)
+39
View File
@@ -0,0 +1,39 @@
#update=initial version
#file=main.zig
const A = enum(u8) { a };
const B = enum(u8) { b };
const Foo = union(A) { a: u8 };
pub fn main(init: std.process.Init) !void {
const field_name = @typeInfo(Foo).@"union".fields[0].name;
var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{});
try stdout_writer.interface.print("{s}\n", .{field_name});
}
const std = @import("std");
#expect_stdout="a\n"
#update=change tag type
#file=main.zig
const A = enum(u8) { a };
const B = enum(u8) { b };
const Foo = union(B) { a: u8 };
pub fn main(init: std.process.Init) !void {
const field_name = @typeInfo(Foo).@"union".fields[0].name;
var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{});
try stdout_writer.interface.print("{s}\n", .{field_name});
}
const std = @import("std");
#expect_error=main.zig:3:24: error: no field named 'a' in enum 'main.B'
#expect_error=main.zig:2:11: note: enum declared here
#update=change field name to match new tag type
#file=main.zig
const A = enum(u8) { a };
const B = enum(u8) { b };
const Foo = union(B) { b: u8 };
pub fn main(init: std.process.Init) !void {
const field_name = @typeInfo(Foo).@"union".fields[0].name;
var stdout_writer = std.Io.File.stdout().writerStreaming(init.io, &.{});
try stdout_writer.interface.print("{s}\n", .{field_name});
}
const std = @import("std");
#expect_stdout="b\n"