mirror of
https://github.com/ziglang/zig.git
synced 2025-12-26 08:03:08 +00:00
24 lines
485 B
Zig
24 lines
485 B
Zig
const std = @import("std");
|
|
const builtin = @import("builtin");
|
|
|
|
const U = union(enum) {
|
|
T: type,
|
|
N: void,
|
|
};
|
|
|
|
fn S(comptime query: U) type {
|
|
return struct {
|
|
fn tag() type {
|
|
return query.T;
|
|
}
|
|
};
|
|
}
|
|
|
|
test "compiler doesn't consider equal unions with different 'type' payload" {
|
|
const s1 = S(U{ .T = u32 }).tag();
|
|
try std.testing.expectEqual(u32, s1);
|
|
|
|
const s2 = S(U{ .T = u64 }).tag();
|
|
try std.testing.expectEqual(u64, s2);
|
|
}
|