authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-02-08 13:24:03+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2026-03-10 10:26:09+00:00
log96d6b22067cccd644190e9b63f8f5bc13b6e93db
tree83bb7c6132731d5c3a6d4183e2f1d586e0d8d2d9
parent4e92592fee6b414757b2e6c088e20ca9a1b21f44
signaturelock-open Commit is signed but in an unrecognized format.

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.

6 files changed, 29 insertions(+), 60 deletions(-)

test/behavior/enum.zig-16
......@@ -823,15 +823,6 @@ test "enum with one member and u1 tag type @intFromEnum" {
823823 try expect(@intFromEnum(Enum.Test) == 0);
824824}
825825
826test "enum with comptime_int tag type" {
827 const Enum = enum(comptime_int) {
828 One = 3,
829 Two = 2,
830 Three = 1,
831 };
832 comptime assert(Tag(Enum) == comptime_int);
833}
834
835826test "enum with one member default to u0 tag type" {
836827 const E0 = enum { X };
837828 comptime assert(Tag(E0) == u0);
......@@ -1274,13 +1265,6 @@ fn getLazyInitialized(param: enum(u8) {
12741265 return @intFromEnum(param);
12751266}
12761267
1277test "Non-exhaustive enum backed by comptime_int" {
1278 const E = enum(comptime_int) { a, b, c, _ };
1279 comptime var e: E = .a;
1280 e = @as(E, @enumFromInt(378089457309184723749));
1281 try expect(@intFromEnum(e) == 378089457309184723749);
1282}
1283
12841268test "matching captures causes enum equivalence" {
12851269 const S = struct {
12861270 fn Nonexhaustive(comptime I: type) type {
test/behavior/union.zig+12-23
......@@ -703,25 +703,23 @@ test "union with only 1 field casted to its enum type which has enum value speci
703703 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
704704
705705 const Literal = union(enum) {
706 Number: f64,
707 Bool: bool,
706 number: f64,
707 bool: bool,
708708 };
709709
710 const ExprTag = enum(comptime_int) {
711 Literal = 33,
712 };
710 const ExprTag = enum(u32) { literal = 33 };
711 const Expr = union(ExprTag) { literal: Literal };
713712
714 const Expr = union(ExprTag) {
715 Literal: Literal,
716 };
713 comptime assert(Tag(ExprTag) == u32);
717714
718 var e = Expr{ .Literal = Literal{ .Bool = true } };
719 _ = &e;
720 comptime assert(Tag(ExprTag) == comptime_int);
721 const t = comptime @as(ExprTag, e);
722 try expect(t == Expr.Literal);
723 try expect(@intFromEnum(t) == 33);
715 var e: Expr = undefined;
716 e = .{ .literal = .{ .bool = true } };
717
718 const t: ExprTag = e;
719 comptime assert(t == Expr.literal);
724720 comptime assert(@intFromEnum(t) == 33);
721 try expect(t == Expr.literal);
722 try expect(@intFromEnum(t) == 33);
725723}
726724
727725test "@intFromEnum works on unions" {
......@@ -893,15 +891,6 @@ test "union no tag with struct member" {
893891 u.foo();
894892}
895893
896test "union with comptime_int tag" {
897 const Union = union(enum(comptime_int)) {
898 X: u32,
899 Y: u16,
900 Z: u8,
901 };
902 comptime assert(Tag(Tag(Union)) == comptime_int);
903}
904
905894test "extern union doesn't trigger field check at comptime" {
906895 const U = extern union {
907896 x: u32,
test/cases/compile_errors/enum_backed_by_comptime_int.zig created+8
......@@ -0,0 +1,8 @@
1const E = enum(comptime_int) { a };
2comptime {
3 _ = E.a;
4}
5
6// error
7//
8// :1:16: error: expected integer tag type, found 'comptime_int'
test/cases/compile_errors/enum_backed_by_comptime_int_must_be_casted_from_comptime_value.zig deleted-12
......@@ -1,12 +0,0 @@
1export fn entry() void {
2 const Tag = enum(comptime_int) { a, b };
3
4 var v: u32 = 0;
5 _ = &v;
6 _ = @as(Tag, @enumFromInt(v));
7}
8
9// error
10//
11// :6:31: error: unable to resolve comptime value
12// :6:31: note: value casted to enum with 'comptime_int' tag type must be comptime-known
test/cases/compile_errors/enum_backed_by_comptime_int_must_be_comptime.zig deleted-9
......@@ -1,9 +0,0 @@
1pub export fn entry() void {
2 const E = enum(comptime_int) { a, b, c, _ };
3 var e: E = .a;
4 _ = &e;
5}
6
7// error
8//
9// :3:12: error: variable of type 'tmp.entry.E' must be const or comptime
test/cases/compile_errors/union_backed_by_enum_backed_by_comptime_int.zig created+9
......@@ -0,0 +1,9 @@
1const U = union(enum(comptime_int)) { a: u32 };
2comptime {
3 const u: U = .{ .a = 123 };
4 _ = u;
5}
6
7// error
8//
9// :1:22: error: expected integer tag type, found 'comptime_int'