#target=x86_64-linux-selfhosted
#target=x86_64-linux-cbe
#target=x86_64-windows-cbe
#target=wasm32-wasi-selfhosted
#update=initial version
#file=main.zig
const Tag = u2;
const Foo = enum(Tag) {
    a,
    b,
    c,
    d,
};
pub fn main() !void {
    var val: Foo = undefined;
    val = .a;
    var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
    try stdout_writer.interface.print("{s}\n", .{@tagName(val)});
}
const std = @import("std");
#expect_stdout="a\n"
#update=too many enum fields
#file=main.zig
const Tag = u2;
const Foo = enum(Tag) {
    a,
    b,
    c,
    d,
    e,
};
pub fn main() !void {
    var val: Foo = undefined;
    val = .a;
    var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
    try stdout_writer.interface.print("{s}\n", .{@tagName(val)});
}
comptime {
    // These can't be true at the same time; analysis should stop as soon as it sees `Foo`
    std.debug.assert(@intFromEnum(Foo.e) == 4);
    std.debug.assert(@TypeOf(@intFromEnum(Foo.e)) == Tag);
}
const std = @import("std");
#expect_error=main.zig:7:5: error: enumeration value '4' too large for type 'u2'
#update=increase tag size
#file=main.zig
const Tag = u3;
const Foo = enum(Tag) {
    a,
    b,
    c,
    d,
    e,
};
pub fn main() !void {
    var val: Foo = undefined;
    val = .a;
    var stdout_writer = std.fs.File.stdout().writerStreaming(&.{});
    try stdout_writer.interface.print("{s}\n", .{@tagName(val)});
}
const std = @import("std");
#expect_stdout="a\n"
