incremental: fix enum resolution bugs

This commit is contained in:
mlugg
2025-01-18 14:18:03 +00:00
parent f38d7a92cc
commit f7b9f84df2
3 changed files with 154 additions and 28 deletions

View File

@@ -0,0 +1,59 @@
#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;
try std.io.getStdOut().writer().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;
try std.io.getStdOut().writer().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=ignored
#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;
try std.io.getStdOut().writer().print("{s}\n", .{@tagName(val)});
}
const std = @import("std");
#expect_stdout="a\n"