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" {...@@ -823,15 +823,6 @@ test "enum with one member and u1 tag type @intFromEnum" {
823 try expect(@intFromEnum(Enum.Test) == 0);823 try expect(@intFromEnum(Enum.Test) == 0);
824}824}
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
835test "enum with one member default to u0 tag type" {826test "enum with one member default to u0 tag type" {
836 const E0 = enum { X };827 const E0 = enum { X };
837 comptime assert(Tag(E0) == u0);828 comptime assert(Tag(E0) == u0);
...@@ -1274,13 +1265,6 @@ fn getLazyInitialized(param: enum(u8) {...@@ -1274,13 +1265,6 @@ fn getLazyInitialized(param: enum(u8) {
1274 return @intFromEnum(param);1265 return @intFromEnum(param);
1275}1266}
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
1284test "matching captures causes enum equivalence" {1268test "matching captures causes enum equivalence" {
1285 const S = struct {1269 const S = struct {
1286 fn Nonexhaustive(comptime I: type) type {1270 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...@@ -703,25 +703,23 @@ test "union with only 1 field casted to its enum type which has enum value speci
703 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO703 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
704704
705 const Literal = union(enum) {705 const Literal = union(enum) {
706 Number: f64,706 number: f64,
707 Bool: bool,707 bool: bool,
708 };708 };
709709
710 const ExprTag = enum(comptime_int) {710 const ExprTag = enum(u32) { literal = 33 };
711 Literal = 33,711 const Expr = union(ExprTag) { literal: Literal };
712 };
713712
714 const Expr = union(ExprTag) {713 comptime assert(Tag(ExprTag) == u32);
715 Literal: Literal,
716 };
717714
718 var e = Expr{ .Literal = Literal{ .Bool = true } };715 var e: Expr = undefined;
719 _ = &e;716 e = .{ .literal = .{ .bool = true } };
720 comptime assert(Tag(ExprTag) == comptime_int);717
721 const t = comptime @as(ExprTag, e);718 const t: ExprTag = e;
722 try expect(t == Expr.Literal);719 comptime assert(t == Expr.literal);
723 try expect(@intFromEnum(t) == 33);
724 comptime assert(@intFromEnum(t) == 33);720 comptime assert(@intFromEnum(t) == 33);
721 try expect(t == Expr.literal);
722 try expect(@intFromEnum(t) == 33);
725}723}
726724
727test "@intFromEnum works on unions" {725test "@intFromEnum works on unions" {
...@@ -893,15 +891,6 @@ test "union no tag with struct member" {...@@ -893,15 +891,6 @@ test "union no tag with struct member" {
893 u.foo();891 u.foo();
894}892}
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
905test "extern union doesn't trigger field check at comptime" {894test "extern union doesn't trigger field check at comptime" {
906 const U = extern union {895 const U = extern union {
907 x: u32,896 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'