The following program, prints:
> zig run typeof.zig
a:comptime_int b:u8 T:u8
> cat typeof.zig
const std = @import("std");
fn foo(a: anytype, b: anytype) void {
const T = @TypeOf(a, b);
std.debug.print("a:{s} b:{s} T:{s}\n", .{
@typeName(@TypeOf(a)),
@typeName(@TypeOf(b)),
@typeName(T),
});
}
pub fn main() void {
const v: u8 = 'a';
foo(32, v);
}
In master testing.zig expectEqual
is declared as:
pub inline fn expectEqual(expected: anytype, actual: anytype) !void {
const T = @TypeOf(expected, actual);
In 0.11.0 testing.zig expectEqual
is declared as:
pub fn expectEqual(expected: anytype, actual: @TypeOf(expected)) !void {
A headache with expectEqual is gone, but how @TypeOf selects the resulting type?