tests: update for accepted language change

'comptime_int' is no longer considered a valid backing type for an enum.
In other words, 'enum(comptime_int)' is a compile error. This change is
accepted to simplify the language.
This commit is contained in:
Matthew Lugg 2026-02-08 13:24:03 +00:00
parent f5ea78d658
commit 1dd1172ed8
No known key found for this signature in database
GPG key ID: 3F5B7DCCBF4AF02E
6 changed files with 29 additions and 60 deletions

View file

@ -823,15 +823,6 @@ test "enum with one member and u1 tag type @intFromEnum" {
try expect(@intFromEnum(Enum.Test) == 0);
}
test "enum with comptime_int tag type" {
const Enum = enum(comptime_int) {
One = 3,
Two = 2,
Three = 1,
};
comptime assert(Tag(Enum) == comptime_int);
}
test "enum with one member default to u0 tag type" {
const E0 = enum { X };
comptime assert(Tag(E0) == u0);
@ -1274,13 +1265,6 @@ fn getLazyInitialized(param: enum(u8) {
return @intFromEnum(param);
}
test "Non-exhaustive enum backed by comptime_int" {
const E = enum(comptime_int) { a, b, c, _ };
comptime var e: E = .a;
e = @as(E, @enumFromInt(378089457309184723749));
try expect(@intFromEnum(e) == 378089457309184723749);
}
test "matching captures causes enum equivalence" {
const S = struct {
fn Nonexhaustive(comptime I: type) type {

View file

@ -703,25 +703,23 @@ test "union with only 1 field casted to its enum type which has enum value speci
if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
const Literal = union(enum) {
Number: f64,
Bool: bool,
number: f64,
bool: bool,
};
const ExprTag = enum(comptime_int) {
Literal = 33,
};
const ExprTag = enum(u32) { literal = 33 };
const Expr = union(ExprTag) { literal: Literal };
const Expr = union(ExprTag) {
Literal: Literal,
};
comptime assert(Tag(ExprTag) == u32);
var e = Expr{ .Literal = Literal{ .Bool = true } };
_ = &e;
comptime assert(Tag(ExprTag) == comptime_int);
const t = comptime @as(ExprTag, e);
try expect(t == Expr.Literal);
try expect(@intFromEnum(t) == 33);
var e: Expr = undefined;
e = .{ .literal = .{ .bool = true } };
const t: ExprTag = e;
comptime assert(t == Expr.literal);
comptime assert(@intFromEnum(t) == 33);
try expect(t == Expr.literal);
try expect(@intFromEnum(t) == 33);
}
test "@intFromEnum works on unions" {
@ -893,15 +891,6 @@ test "union no tag with struct member" {
u.foo();
}
test "union with comptime_int tag" {
const Union = union(enum(comptime_int)) {
X: u32,
Y: u16,
Z: u8,
};
comptime assert(Tag(Tag(Union)) == comptime_int);
}
test "extern union doesn't trigger field check at comptime" {
const U = extern union {
x: u32,

View file

@ -0,0 +1,8 @@
const E = enum(comptime_int) { a };
comptime {
_ = E.a;
}
// error
//
// :1:16: error: expected integer tag type, found 'comptime_int'

View file

@ -1,12 +0,0 @@
export fn entry() void {
const Tag = enum(comptime_int) { a, b };
var v: u32 = 0;
_ = &v;
_ = @as(Tag, @enumFromInt(v));
}
// error
//
// :6:31: error: unable to resolve comptime value
// :6:31: note: value casted to enum with 'comptime_int' tag type must be comptime-known

View file

@ -1,9 +0,0 @@
pub export fn entry() void {
const E = enum(comptime_int) { a, b, c, _ };
var e: E = .a;
_ = &e;
}
// error
//
// :3:12: error: variable of type 'tmp.entry.E' must be const or comptime

View file

@ -0,0 +1,9 @@
const U = union(enum(comptime_int)) { a: u32 };
comptime {
const u: U = .{ .a = 123 };
_ = u;
}
// error
//
// :1:22: error: expected integer tag type, found 'comptime_int'